| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7-- |
| 004 | (* |
| 005 |
|
| 006 | プロファイルインストール用のぺルパ |
| 007 |
|
| 008 | v1 初回作成 |
| 009 | v2 色々試して 結局1ファイル毎処理は仕様なのでこの方式に落ち着いた |
| 010 |
|
| 011 |
|
| 012 | com.cocolog-nifty.quicktimer.icefloe *) |
| 013 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7-- |
| 014 | use AppleScript version "2.8" |
| 015 | use framework "Foundation" |
| 016 | use framework "AppKit" |
| 017 | use scripting additions |
| 018 |
|
| 019 | property refMe : a reference to current application |
| 020 | ############################ |
| 021 | #RUN |
| 022 | # on run {argAliasFilePath} |
| 023 |
|
| 024 |
|
| 025 | on run |
| 026 | #ダイアログ |
| 027 | set appFileManager to refMe's NSFileManager's defaultManager() |
| 028 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask)) |
| 029 | set ocidDesktopDirPathURL to ocidURLsArray's firstObject() |
| 030 | set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias |
| 031 | set listUTI to {"com.apple.mobileconfig"} as list |
| 032 | set appBundle to current application's NSBundle's bundleWithIdentifier:("com.apple.osax.standardadditions") |
| 033 | set strChooseAFile to (appBundle's localizedStringForKey:("Choose a File") value:("Choose a File") table:("Localizable")) as text |
| 034 | set appBundle to current application's NSBundle's bundleWithIdentifier:("com.apple.AppKit") |
| 035 | set strMultiple to (appBundle's localizedStringForKey:("NSMultipleDocuments") value:("NSMultipleDocuments") table:("AccessibilityImageDescriptions")) as text |
| 036 | set strMes to ("com.apple.mobileconfig " & strMultiple & return & strChooseAFile & "") as text |
| 037 | set strPrompt to ("com.apple.mobileconfig " & strMultiple & return & strChooseAFile & "") as text |
| 038 | try |
| 039 | tell application "SystemUIServer" |
| 040 | activate |
| 041 | set listAliasFilePath to (choose file strMes with prompt strPrompt default location aliasDefaultLocation of type listUTI with invisibles and multiple selections allowed without showing package contents) as list |
| 042 | end tell |
| 043 | on error strErrMes number numErrNo |
| 044 | log strErrMes & numErrNo |
| 045 | return false |
| 046 | end try |
| 047 | if listAliasFilePath is {} then |
| 048 | return false |
| 049 | end if |
| 050 | |
| 051 | |
| 052 | set boolDone to (open listAliasFilePath) as boolean |
| 053 | return boolDone |
| 054 | |
| 055 | end run |
| 056 |
|
| 057 |
|
| 058 | ############################ |
| 059 | #open |
| 060 | on open listAliasFilePath |
| 061 | |
| 062 | set boolDone to doOpenSystemPreferences() |
| 063 | if boolDone is false then |
| 064 | set boolDone to doOpenSystemPreferences() |
| 065 | end if |
| 066 | |
| 067 | |
| 068 | set listTargetFilePath to {} as list |
| 069 | |
| 070 | repeat with itemAliasFilePath in listAliasFilePath |
| 071 | set aliasFilePath to itemAliasFilePath as alias |
| 072 | set recordInfoFor to (info for aliasFilePath) as record |
| 073 | set strUTI to (type identifier of recordInfoFor) as text |
| 074 | if strUTI is "com.apple.mobileconfig" then |
| 075 | set end of listTargetFilePath to aliasFilePath |
| 076 | end if |
| 077 | end repeat |
| 078 | |
| 079 | |
| 080 | #リストで投げる方法(期待動作しない) |
| 081 | (* |
| 082 | tell application id "com.apple.mcx.ProfileHelper" |
| 083 | open listTargetFilePath |
| 084 | end tell |
| 085 | *) |
| 086 | #ひとつづつ投げるタイプ |
| 087 | |
| 088 | repeat with itemTargetFilePath in listTargetFilePath |
| 089 | set aliasTargetFilePath to itemTargetFilePath as alias |
| 090 | set strTargetFilePath to POSIX path of aliasTargetFilePath |
| 091 | set boolDone to doOpenMobileConfig(strTargetFilePath) |
| 092 | if boolDone is false then |
| 093 | set boolDone to doOpenMobileConfig(strTargetFilePath) |
| 094 | end if |
| 095 | set strMsg to ("プロファイルを" & return & "システム設定画面で処理してください") as text |
| 096 | set strOKButton to ("処理が終わりました次へ") as text |
| 097 | set strCancelButton to ("キャンセル") as text |
| 098 | set listButton to {strOKButton, strCancelButton} as list |
| 099 | |
| 100 | tell application "SystemUIServer" |
| 101 | activate |
| 102 | try |
| 103 | set recordResponse to (display alert strMsg buttons listButton default button strOKButton cancel button strCancelButton as critical giving up after 360) as record |
| 104 | on error strErrMsg number numErrNo |
| 105 | log strErrMsg & numErrNo |
| 106 | return false |
| 107 | end try |
| 108 | end tell |
| 109 | if (gave up of recordResponse) is true then |
| 110 | log "時間切れですやりなおしてください" |
| 111 | return false |
| 112 | else if strOKButton is equal to (button returned of recordResponse) then |
| 113 | set strResponse to (button returned of recordResponse) as text |
| 114 | else if strCancelButton is equal to (button returned of recordResponse) then |
| 115 | return false |
| 116 | end if |
| 117 | |
| 118 | end repeat |
| 119 | |
| 120 | (* |
| 121 | #まとめて投げるタイプ 期待動作しない |
| 122 | set strArgText to ("") as text |
| 123 | repeat with itemTargetFilePath in listTargetFilePath |
| 124 | set aliasTargetFilePath to itemTargetFilePath as alias |
| 125 | set strTargetFilePath to POSIX path of aliasTargetFilePath |
| 126 | set strArgText to ("" & strArgText & " \"" & strTargetFilePath & "\" " & "") as text |
| 127 | end repeat |
| 128 | set boolDone to doOpenMobileConfigArgs(strArgText) |
| 129 | *) |
| 130 | |
| 131 | |
| 132 | return true |
| 133 | |
| 134 | end open |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 | ############################ |
| 139 | #doOpenMobileConfig |
| 140 | on doOpenMobileConfigArgs(strArgText) |
| 141 | set strArgText to strArgText as text |
| 142 | try |
| 143 | set strURL to ("x-apple.systempreferences:com.apple.preferences.configurationprofiles") as text |
| 144 | set theCmdCom to ("/usr/bin/open " & strArgText & "| /usr/bin/open \"" & strURL & "\"") as text |
| 145 | do shell script theCmdCom |
| 146 | on error strErrMsg number numErrNo |
| 147 | log "No: " & numErrNo & linefeed & "Error:" & strErrMsg |
| 148 | return false |
| 149 | end try |
| 150 | return true |
| 151 | end doOpenMobileConfigArgs |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 | ############################ |
| 157 | #doOpenMobileConfig |
| 158 | on doOpenMobileConfig(strTargetFilePath) |
| 159 | set strFilePath to strTargetFilePath as text |
| 160 | try |
| 161 | set strURL to ("x-apple.systempreferences:com.apple.preferences.configurationprofiles") as text |
| 162 | set theCmdCom to ("/usr/bin/open \"" & strFilePath & "\" | /usr/bin/open \"" & strURL & "\"") as text |
| 163 | do shell script theCmdCom |
| 164 | on error strErrMsg number numErrNo |
| 165 | log "No: " & numErrNo & linefeed & "Error:" & strErrMsg |
| 166 | return false |
| 167 | end try |
| 168 | return true |
| 169 | end doOpenMobileConfig |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 | ############################ |
| 177 | #doOpenSystemPreferences |
| 178 | on doOpenSystemPreferences() |
| 179 | tell application id "com.apple.systempreferences" to quit |
| 180 | delay 1 |
| 181 | tell application id "com.apple.systempreferences" to activate |
| 182 | tell application "System Settings" to activate |
| 183 | --システム環境設定が開くのを待つ |
| 184 | repeat |
| 185 | set doLaunchApp to get running of application "System Settings" |
| 186 | if doLaunchApp is false then |
| 187 | delay 0.5 |
| 188 | else |
| 189 | exit repeat |
| 190 | end if |
| 191 | end repeat |
| 192 | try |
| 193 | set strPath to ("/System/Library/PreferencePanes/Profiles.prefPane") as text |
| 194 | set strCommandText to "/usr/bin/open -b com.apple.systempreferences \"" & strPath & "\"" as text |
| 195 | do shell script strCommandText |
| 196 | on error strErrMsg number numErrNo |
| 197 | log "No: " & numErrNo & linefeed & "Error:" & strErrMsg |
| 198 | tell application id "com.apple.systempreferences" |
| 199 | activate |
| 200 | try |
| 201 | reveal anchor "Main" of pane id "com.apple.Profiles-Settings.extension" |
| 202 | on error strErrMsg number numErrNo |
| 203 | log "No: " & numErrNo & linefeed & "Error:" & strErrMsg |
| 204 | return false |
| 205 | end try |
| 206 | end tell |
| 207 | end try |
| 208 | |
| 209 | repeat 10 times |
| 210 | tell application id "com.apple.systempreferences" |
| 211 | activate |
| 212 | try |
| 213 | reveal anchor "Main" of pane id "com.apple.Profiles-Settings.extension" |
| 214 | on error strErrMsg number numErrNo |
| 215 | log "No: " & numErrNo & linefeed & "Error:" & strErrMsg |
| 216 | return false |
| 217 | end try |
| 218 | tell current pane |
| 219 | set strPaneID to id as text |
| 220 | # properties |
| 221 | end tell |
| 222 | end tell |
| 223 | if strPaneID is "com.apple.Profiles-Settings.extension" then |
| 224 | exit repeat |
| 225 | else |
| 226 | delay 0.5 |
| 227 | end if |
| 228 | end repeat |
| 229 | |
| 230 | return true |
| 231 | |
| 232 | end doOpenSystemPreferences |