001 | #!/usr/bin/env osascript |
---|
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
---|
003 | #com.cocolog-nifty.quicktimer.icefloe |
---|
004 | # バンドルIDからアプリケーションのバージョンを取得する |
---|
005 | # アプリケーションを起動させない |
---|
006 | # iOSアプリも対応させたいと思ったらこうなった |
---|
007 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
---|
008 | use AppleScript version "2.8" |
---|
009 | use framework "Foundation" |
---|
010 | use framework "AppKit" |
---|
011 | use scripting additions |
---|
012 | property refMe : a reference to current application |
---|
013 | |
---|
014 | #バンドルID |
---|
015 | set strBundleID to ("com.xrite.pantone.pantoneconnect") as text |
---|
016 | #想定されるパス |
---|
017 | set strPresAppPath to ("~/Applications/Pantone Connect.app") as text |
---|
018 | |
---|
019 | ############## |
---|
020 | #アプリケーションのパス取得 |
---|
021 | set refResponse to doChkAppPath(strBundleID, strPresAppPath) |
---|
022 | if refResponse is false then |
---|
023 | return "アプリケーションが見つかりませんでした" |
---|
024 | else |
---|
025 | set {strAppPath, ocidAppPathURL} to refResponse |
---|
026 | end if |
---|
027 | log strAppPath |
---|
028 | |
---|
029 | ############## |
---|
030 | #バージョン取得 |
---|
031 | set refResponse to doGetAppVerSion(ocidAppPathURL) |
---|
032 | if refResponse is false then |
---|
033 | return "アプリケーションのバージョン不明" |
---|
034 | else |
---|
035 | set {ocidVersion, ocidVersionString} to refResponse |
---|
036 | end if |
---|
037 | log ocidVersion as text |
---|
038 | log ocidVersionString as text |
---|
039 | |
---|
040 | |
---|
041 | return |
---|
042 | |
---|
043 | ########################## |
---|
044 | #【A】インストール済みチェック |
---|
045 | to doChkAppPath(argBundleID, argPresAppPath) |
---|
046 | set appFileManager to refMe's NSFileManager's defaultManager() |
---|
047 | set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(argBundleID)) |
---|
048 | if ocidAppBundle = (missing value) then |
---|
049 | #バンドルで見つからない場合 NSWorkspace |
---|
050 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
---|
051 | set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(argBundleID)) |
---|
052 | if ocidAppPathURL = (missing value) then |
---|
053 | #AppKitで見つからない場合 Finder |
---|
054 | try |
---|
055 | tell application "Finder" |
---|
056 | set aliasAppApth to (application file id argBundleID) as alias |
---|
057 | set strAppPath to (POSIX path of aliasAppApth) as text |
---|
058 | end tell |
---|
059 | set ocidAppPathStr to (refMe's NSString's stringWithString:(strAppPath)) |
---|
060 | set ocidAppPath to ocidAppPathStr's stringByStandardizingPath() |
---|
061 | set ocidAppPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidAppPath) isDirectory:true) |
---|
062 | on error |
---|
063 | set ocidPresAppPathStr to (refMe's NSString's stringWithString:(argPresAppPath)) |
---|
064 | set ocidPresAppPath to ocidPresAppPathStr's stringByStandardizingPath() |
---|
065 | set ocidPresAppPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidPresAppPath) isDirectory:true) |
---|
066 | set boolDirExists to appFileManager's fileExistsAtPath:(ocidPresAppPath) isDirectory:(missing value) |
---|
067 | if boolDirExists is true then |
---|
068 | set ocidAppPath to ocidPresAppPath |
---|
069 | set ocidAppPathURL to ocidPresAppPathURL |
---|
070 | else if boolDirExists is false then |
---|
071 | log "アプケーションを発見できません" |
---|
072 | return false |
---|
073 | end if |
---|
074 | end try |
---|
075 | end if |
---|
076 | else |
---|
077 | #バンドルで見つかる場合 |
---|
078 | set ocidAppPathURL to ocidAppBundle's bundleURL() |
---|
079 | end if |
---|
080 | ########################## |
---|
081 | #本当にあるか?チェック |
---|
082 | set ocidAppPath to ocidAppPathURL's |path|() |
---|
083 | set boolDirExists to appFileManager's fileExistsAtPath:(ocidAppPath) isDirectory:(missing value) |
---|
084 | if boolDirExists is true then |
---|
085 | log "インストール済み" |
---|
086 | else if boolDirExists is false then |
---|
087 | #見つからない Finderで再チェック |
---|
088 | tell application "Finder" |
---|
089 | set aliasAppApth to (application file id argBundleID) as alias |
---|
090 | set strAppPath to (POSIX path of aliasAppApth) as text |
---|
091 | end tell |
---|
092 | set ocidAppPathStr to (refMe's NSString's stringWithString:(strAppPath)) |
---|
093 | set ocidAppPath to ocidAppPathStr's stringByStandardizingPath() |
---|
094 | set ocidAppPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidAppPath) isDirectory:true) |
---|
095 | set strAppPath to ocidAppPathURL's |path|() as text |
---|
096 | set boolDirExists to appFileManager's fileExistsAtPath:(ocidAppPath) isDirectory:(missing value) |
---|
097 | #Finderで見つかった |
---|
098 | if boolDirExists is true then |
---|
099 | set listResponse to {strAppPath, ocidAppPathURL} as list |
---|
100 | return listResponse |
---|
101 | else if boolDirExists is false then |
---|
102 | #想定パスも探す |
---|
103 | set ocidPresAppPathStr to (refMe's NSString's stringWithString:(argPresAppPath)) |
---|
104 | set ocidPresAppPath to ocidPresAppPathStr's stringByStandardizingPath() |
---|
105 | set ocidPresAppPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidPresAppPath) isDirectory:true) |
---|
106 | set boolDirExists to appFileManager's fileExistsAtPath:(ocidPresAppPath) isDirectory:(missing value) |
---|
107 | if boolDirExists is true then |
---|
108 | set strAppPath to ocidPresAppPathURL's |path|() as text |
---|
109 | set listResponse to {strAppPath, ocidAppPathURL} as list |
---|
110 | return listResponse |
---|
111 | else if boolDirExists is false then |
---|
112 | log "アプケーションを発見できません" |
---|
113 | return false |
---|
114 | end if |
---|
115 | end if |
---|
116 | end if |
---|
117 | set strAppPath to ocidAppPathURL's |path|() as text |
---|
118 | set listResponse to {strAppPath, ocidAppPathURL} as list |
---|
119 | return listResponse |
---|
120 | end doChkAppPath |
---|
121 | |
---|
122 | |
---|
123 | ########################## |
---|
124 | #【B】アプリケーションのバージョンの取得 |
---|
125 | to doGetAppVerSion(argAppPathURL) |
---|
126 | set ocidBundle to refMe's NSBundle's bundleWithURL:(argAppPathURL) |
---|
127 | set ocidInfoDict to ocidBundle's infoDictionary() |
---|
128 | set ocidVersionString to (ocidInfoDict's valueForKey:("CFBundleShortVersionString")) |
---|
129 | set ocidVersion to (ocidInfoDict's valueForKey:("CFBundleVersion")) |
---|
130 | return {ocidVersion, ocidVersionString} |
---|
131 | end doGetAppVerSion |
---|