VMware InstallBuilder 24.
| 固定リンク
行番号 | ソース |
---|---|
001 | #!/bin/bash |
002 | # インストールPKGの情報の収集 |
003 | #実行ユーザー |
004 | STAT_USR=$(/usr/bin/stat -f%Su /dev/console) |
005 | /bin/echo "STAT_USR(console): $STAT_USR" |
006 | STR_OUTPUT_STRING="ユーザーID: ${STAT_USR}\n" |
007 | #OSバージョン |
008 | STR_VALUE=$(/usr/libexec/PlistBuddy -c "Print:ProductVersion" "/System/Library/CoreServices/SystemVersion.plist") |
009 | STR_OUTPUT_STRING="${STR_OUTPUT_STRING}OSver: ${STR_VALUE}\n\n" |
010 | #テンポラリー(テキストファイルの保存先 再起動時に自動削除) |
011 | STR_CONF_DIR=$(/usr/bin/sudo -u "$STAT_USR" /usr/bin/getconf "DARWIN_USER_TEMP_DIR") |
012 | /bin/echo "DARWIN_USER_TEMP_DIR: $STR_CONF_DIR" |
013 | STR_UUID=$(/usr/bin/uuidgen) |
014 | STR_TMP_DIR_PATH="${STR_CONF_DIR}/getPkgInfo.${STR_UUID}" |
015 | TMP_DIR=$(/usr/bin/sudo -u "$STAT_USR" /usr/bin/mktemp -d "$STR_TMP_DIR_PATH") |
016 | /bin/echo "TMP_DIR: $TMP_DIR" |
017 | #保存ファイル名とパス |
018 | STR_SAVE_FILE_NAME="PKGINFO.txt" |
019 | PATH_SAVE_FILE="${TMP_DIR}/${STR_SAVE_FILE_NAME}" |
020 | #Libraryチェック |
021 | PATH_PLIST="/Library/Receipts/InstallHistory.plist" |
022 | STR_RESPONSE=$(/usr/libexec/PlistBuddy -c "Print:" "$PATH_PLIST" | tr -d '\n\t ') |
023 | NUM_CNT_ARRAY=$(/bin/echo "$STR_RESPONSE" | grep -o "Dict" | wc -l | tr -d ' ') |
024 | STR_OUTPUT_STRING="${STR_OUTPUT_STRING}総件数: ${NUM_CNT_ARRAY}\n\n" |
025 | #主要データのみテキストにする |
026 | for ((itemNO = 0; itemNO <= (NUM_CNT_ARRAY - 1); itemNO++)); do |
027 | STR_VALUE=$(/usr/libexec/PlistBuddy -c "Print:${itemNO}:date" "$PATH_PLIST") |
028 | STR_OUTPUT_STRING="${STR_OUTPUT_STRING}${STR_VALUE}" |
029 | STR_VALUE=$(/usr/libexec/PlistBuddy -c "Print:${itemNO}:displayName" "$PATH_PLIST") |
030 | STR_OUTPUT_STRING="${STR_OUTPUT_STRING}\n${STR_VALUE}" |
031 | STR_VALUE=$(/usr/libexec/PlistBuddy -c "Print:${itemNO}:packageIdentifiers:0" "$PATH_PLIST") |
032 | STR_OUTPUT_STRING="${STR_OUTPUT_STRING}\n${STR_VALUE}\n\n" |
033 | done |
034 | # var/db チェック |
035 | PATH_DB_DIR="/private/var/db/receipts" |
036 | #LIST_FILE_NAME=$(/bin/ls "${PATH_DB_DIR}") |
037 | LIST_FILE_NAME=("$PATH_DB_DIR"/*) |
038 | #LIST_FILE_NAME=$(/usr/bin/find "$PATH_DB_DIR" -type f) |
039 | STR_OUTPUT_STRING="${STR_OUTPUT_STRING}\n■PLIST\n" |
040 | for ITEM_FILENAME in "${LIST_FILE_NAME[@]}"; do |
041 | # /bin/echo "${PATH_DB_DIR}/${ITEM_FILENAME}" |
042 | STR_EXTENSION="${ITEM_FILENAME##*.}" |
043 | if [[ "$STR_EXTENSION" == "plist" ]]; then |
044 | #PLISTの内容を取得 |
045 | STR_OUTPUT_STRING="${STR_OUTPUT_STRING}\n\n${ITEM_FILENAME}" |
046 | STR_VALUE=$(/usr/libexec/PlistBuddy -c "Print:InstallDate" "$ITEM_FILENAME") |
047 | STR_OUTPUT_STRING="${STR_OUTPUT_STRING}\nInstallDate: ${STR_VALUE}" |
048 | STR_VALUE=$(/usr/libexec/PlistBuddy -c "Print:PackageFileName" "$ITEM_FILENAME") |
049 | STR_OUTPUT_STRING="${STR_OUTPUT_STRING}\nPackageFileName: ${STR_VALUE}" |
050 | STR_VALUE=$(/usr/libexec/PlistBuddy -c "Print:PackageIdentifier" "$ITEM_FILENAME") |
051 | STR_OUTPUT_STRING="${STR_OUTPUT_STRING}\nPackageIdentifier: ${STR_VALUE}" |
052 | STR_VALUE=$(/usr/libexec/PlistBuddy -c "Print:InstallPrefixPath" "$ITEM_FILENAME") |
053 | STR_OUTPUT_STRING="${STR_OUTPUT_STRING}\nInstallPrefixPath: ${STR_VALUE}" |
054 | STR_VALUE=$(/usr/libexec/PlistBuddy -c "Print:PackageFileName" "$ITEM_FILENAME") |
055 | STR_OUTPUT_STRING="${STR_OUTPUT_STRING}\nPackageFileName: ${STR_VALUE}\n\n" |
056 | fi |
057 | done |
058 | |
059 | STR_OUTPUT_STRING="${STR_OUTPUT_STRING}\n■BOM:\n" |
060 | for ITEM_FILENAME in "${LIST_FILE_NAME[@]}"; do |
061 | # /bin/echo "${PATH_DB_DIR}/${ITEM_FILENAME}" |
062 | STR_EXTENSION="${ITEM_FILENAME##*.}" |
063 | if [[ "$STR_EXTENSION" == "bom" ]]; then |
064 | #BOMの内容を取得 |
065 | STR_BOM_TEXT=$(/usr/bin/lsbom -sf "${ITEM_FILENAME}") |
066 | STR_OUTPUT_STRING="${STR_OUTPUT_STRING}\n\n${LIST_FILE_NAME}" |
067 | STR_OUTPUT_STRING="${STR_OUTPUT_STRING}\n${STR_BOM_TEXT}\n\n" |
068 | fi |
069 | done |
070 | |
071 | #保存して |
072 | /usr/bin/printf "$STR_OUTPUT_STRING" >"$PATH_SAVE_FILE" |
073 | #開く |
074 | /usr/bin/open -b "com.apple.TextEdit" "$PATH_SAVE_FILE" |
075 | |
076 | exit 0 |
AppleScriptで生成しました |
| 固定リンク
Managed Installs
https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/SoftwareDistribution4/Managed_Installs/Managed_Installs.html#//apple_ref/doc/uid/TP40004615-CH6-SW9
Jamf Composer - a Mac package manager
https://app.jamfnow.com/account/composer
Composer User Guide
https://docs.jamf.com/composer/10.27.0/user-guide/Composer_Overview.html
Building and Signing Mac Packages
https://learn.jamf.com/bundle/jamf-now-documentation/page/Building_and_Signing_Mac_Packages.html
Packages
http://s.sudre.free.fr/Software/Packages/about.html
Iceberg
http://s.sudre.free.fr/Software/Iceberg.html
Suspicious Package
https://mothersruin.com/software/SuspiciousPackage/
Pacifist
https://www.charlessoft.com
script-to-package-tool-for-macos
https://github.com/SAP/script-to-package-tool-for-macos
quickpkg
https://github.com/scriptingosx/quickpkg
| 固定リンク
行番号 | ソース |
---|---|
001 | #! /usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | # |
004 | # |
005 | #V3フォルダ名を明確にした |
006 | #V4解凍のコマンドを変更 |
007 | # com.cocolog-nifty.quicktimer.icefloe |
008 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
009 | ##自分環境がos12なので2.8にしているだけです |
010 | use AppleScript version "2.8" |
011 | use framework "Foundation" |
012 | use framework "AppKit" |
013 | use scripting additions |
014 | |
015 | |
016 | property refMe : a reference to current application |
017 | |
018 | ######ファイルのオープン |
019 | on run |
020 | set theWithPrompt to "flat packageを拡張してbundles packageに変換します" |
021 | set theDefLoc to path to downloads folder from user domain |
022 | set theFileTypeList to {"com.apple.installer-package-archive"} as list |
023 | set aliasFilePathAlias to (choose file default location theDefLoc ¬ |
024 | with prompt theWithPrompt ¬ |
025 | of type theFileTypeList ¬ |
026 | invisibles true ¬ |
027 | with showing package contents without multiple selections allowed) |
028 | open aliasFilePathAlias |
029 | end run |
030 | |
031 | ######ドロップのオープン |
032 | on open aliasFilePathAlias |
033 | |
034 | set appFileManager to refMe's NSFileManager's defaultManager() |
035 | set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace() |
036 | |
037 | ####選択したパッケージのパス |
038 | set strOrigFilePath to POSIX path of aliasFilePathAlias as text |
039 | set ocidOrigPkgFilePath to (refMe's NSString's stringWithString:strOrigFilePath) |
040 | set ocidOrigFileName to ocidOrigPkgFilePath's lastPathComponent() |
041 | set strBaseFileName to ocidOrigFileName's stringByDeletingPathExtension() |
042 | |
043 | ####ユーザーダウンロードフォルダ |
044 | set ocidUserDownloadsPathArray to (appFileManager's URLsForDirectory:(refMe's NSDownloadsDirectory) inDomains:(refMe's NSUserDomainMask)) |
045 | set ocidUserDownloadsPathURL to ocidUserDownloadsPathArray's objectAtIndex:0 |
046 | #####展開フォルダ名 |
047 | set strDirName to ("解凍済" & strBaseFileName) as text |
048 | set ocidSaveDirPathURL to ocidUserDownloadsPathURL's URLByAppendingPathComponent:(strDirName) |
049 | ###フォルダを作る |
050 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0 |
051 | ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions) |
052 | set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference) |
053 | |
054 | |
055 | ###pkgの展開先 |
056 | set ocidExpandPkgPathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strBaseFileName) |
057 | set strSaveDirPathURL to ocidExpandPkgPathURL's |path|() as text |
058 | ####コマンド実行 |
059 | set theComandText to "/usr/sbin/pkgutil --expand-full \"" & strOrigFilePath & "\" \"" & strSaveDirPathURL & "\"" as text |
060 | do shell script theComandText |
061 | ####展開 パッケージを調べて |
062 | set listResult to appFileManager's contentsOfDirectoryAtURL:ocidExpandPkgPathURL includingPropertiesForKeys:{refMe's NSURLPathKey} options:0 |error| :(reference) |
063 | set listFilePathURLArray to item 1 of listResult |
064 | ####内包されているファイル |
065 | repeat with itemFilePathURLArray in listFilePathURLArray |
066 | ####拡張子PKGだけ実施 |
067 | set strExtension to itemFilePathURLArray's pathExtension() as text |
068 | if strExtension is "pkg" then |
069 | set ocidPkgName to itemFilePathURLArray's lastPathComponent() |
070 | |
071 | #####Payloadをdittoする |
072 | set strPkgFolderName to (ocidPkgName as text) & "_Folder" |
073 | set ocidDistPathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:strPkgFolderName) |
074 | set boolMoveFileAndRename to (appFileManager's moveItemAtURL:itemFilePathURLArray toURL:ocidDistPathURL |error| :(reference)) |
075 | set ocidPayLoardPathURL to (ocidDistPathURL's URLByAppendingPathComponent:"Payload") |
076 | set strPayLoardPathURL to ocidPayLoardPathURL's |path|() as text |
077 | set strSaveDirPathURL to (ocidPayLoardPathURL's URLByDeletingLastPathComponent())'s |path|() as text |
078 | #####解凍コピー |
079 | try |
080 | set theComandText to ("/usr/bin/ditto -xz \"" & strPayLoardPathURL & "\" \"" & strSaveDirPathURL & "\"") as text |
081 | do shell script theComandText |
082 | end try |
083 | end if |
084 | end repeat |
085 | ############################# |
086 | ###Finderでフォルダを開く |
087 | ############################# |
088 | appShardWorkspace's openURL:ocidExpandPkgPathURL |
089 | end open |
AppleScriptで生成しました |
| 固定リンク
行番号 | ソース |
---|---|
001 | #! /usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | #com.cocolog-nifty.quicktimer.icefloe |
004 | # 【注意事項】必ず 『実行専用』の『アプリケーション』にしてください |
005 | #管理者パスワードが平文で記述される事になりますので |
006 | #セキュリティには留意ください |
007 | #また |
008 | #厳密にはログに管理者パスワードが平文で流れますので |
009 | #使用はインハウス等に限定された方がいいかもしれません |
010 | # |
011 | #v2 パスワードチェックを最初にやるように変更 |
012 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
013 | use AppleScript version "2.8" |
014 | use framework "Foundation" |
015 | use framework "AppKit" |
016 | use scripting additions |
017 | |
018 | property refMe : a reference to current application |
019 | |
020 | ###################################### |
021 | #設定項目 |
022 | #インストールするパッケージのURL(DMGじゃダメよ) |
023 | set strPkgURL to ("https://ardownload3.adobe.com/pub/adobe/acrobat/mac/AcrobatDC/2400220857/AcroRdrSCADC2400220857_MUI.pkg") as text |
024 | |
025 | #管理者ユーザー名(ショート) |
026 | set strAdminUserName to ("admin") as text |
027 | #管理者パスワード |
028 | set strAuthPW to ("管理者パスワード") as text |
029 | #報告メールの送信先 |
030 | property strAdminEmail : ("foo@hoge.com") as text |
031 | |
032 | ###################################### |
033 | #何はなくても最初にパスワードチェック |
034 | set strCommandText to ("/usr/bin/sudo /bin/date") as text |
035 | log strCommandText |
036 | try |
037 | do shell script strCommandText user name strAdminUserName password strAuthPW with administrator privileges |
038 | on error |
039 | log doDialog("パスワードチェックでエラーしました\nパスワードが違います") |
040 | return "パスワードが違います" |
041 | end try |
042 | ###################################### |
043 | #保存先 ダウンロードフォルダ ocidDownloadDirPathURL |
044 | set appFileManager to refMe's NSFileManager's defaultManager() |
045 | set ocidTempDirURL to appFileManager's temporaryDirectory() |
046 | set ocidUUID to refMe's NSUUID's alloc()'s init() |
047 | set ocidUUIDString to ocidUUID's UUIDString |
048 | set ocidDownloadDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:(true) |
049 | #フォルダを作る これだけアクセス権777 |
050 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0 |
051 | ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions) |
052 | set listDone to appFileManager's createDirectoryAtURL:(ocidDownloadDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error| :(reference) |
053 | if (item 1 of listDone) is true then |
054 | log "【1】正常処理" |
055 | set ocidLogFilePathURL to ocidDownloadDirPathURL's URLByAppendingPathComponent:("_このフォルダは削除しても大丈夫です.txt") isDirectory:(false) |
056 | set ocidLogStr to refMe's NSString's stringWithString:("このフォルダは削除しても大丈夫です") |
057 | set listDone to ocidLogStr's writeToURL:(ocidLogFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error| :(reference) |
058 | if (item 1 of listDone) is true then |
059 | set strLogFilePath to (ocidLogFilePathURL's |path|()) as text |
060 | log "【2】正常処理" |
061 | else if (item 2 of listDone) ≠ (missing value) then |
062 | set strErrorNo to (item 2 of listDone)'s code() as text |
063 | set strDescription to (item 2 of listDone)'s localizedDescription() as text |
064 | log doDialog("【2】でエラーしました\n" & strErrorNo & "\n" & strDescription) |
065 | return "エラーしました" |
066 | end if |
067 | |
068 | else if (item 2 of listDone) ≠ (missing value) then |
069 | set strErrorNo to (item 2 of listDone)'s code() as text |
070 | set strDescription to (item 2 of listDone)'s localizedDescription() as text |
071 | log doDialog("【1】でエラーしました\n" & strErrorNo & "\n" & strDescription) |
072 | return "エラーしました" |
073 | end if |
074 | ###################################### |
075 | #ダウンロード 本処理 |
076 | set ocidURLString to refMe's NSString's stringWithString:(strPkgURL) |
077 | set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidURLString) |
078 | set strURL to ocidURL's absoluteString() as text |
079 | set ocidFileName to ocidURL's lastPathComponent() |
080 | set strFileName to ocidFileName as text |
081 | #保存パス |
082 | set ocidSavePkgFilePathURL to ocidDownloadDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:(false) |
083 | set strSavePkgFilePath to (ocidSavePkgFilePathURL's |path|()) as text |
084 | #NSDATA |
085 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
086 | set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidURL) options:(ocidOption) |error| :(reference) |
087 | if (item 2 of listResponse) = (missing value) then |
088 | log "【3】正常処理" |
089 | set ocidReadData to (item 1 of listResponse) |
090 | #writeToURL |
091 | set ocidOption to (refMe's NSDataWritingAtomic) |
092 | set listDone to ocidReadData's writeToURL:(ocidSavePkgFilePathURL) options:(ocidOption) |error| :(reference) |
093 | if (item 1 of listDone) is true then |
094 | log "【4】正常処理" |
095 | else if (item 2 of listDone) ≠ (missing value) then |
096 | set strErrorNo to (item 2 of listDone)'s code() as text |
097 | set strDescription to (item 2 of listDone)'s localizedDescription() as text |
098 | log doDialog("【4】でエラーしました\n" & strErrorNo & "\n" & strDescription) |
099 | return "エラーしました" |
100 | end if |
101 | else if (item 2 of listResponse) ≠ (missing value) then |
102 | log "initWithContentsOfURL エラーしました CULRを試します" |
103 | #CULR |
104 | set strCommandText to ("/usr/bin/curl -v -L -o \"" & strSavePkgFilePath & "\" \"" & strURL & "\" --connect-timeout 20 >> \"" & strLogFilePath & "\" 2>>&1") as text |
105 | log strCommandText |
106 | try |
107 | do shell script strCommandText |
108 | on error |
109 | set strErrorNo to (item 2 of listResponse)'s code() as text |
110 | set strDescription to (item 2 of listResponse)'s localizedDescription() as text |
111 | log doDialog("【3】でエラーしました\n" & strErrorNo & "\n" & strDescription) |
112 | return "CURL エラーしました" |
113 | end try |
114 | end if |
115 | ###################################### |
116 | #インストール本処理 |
117 | set strCommandText to ("/usr/bin/sudo /usr/sbin/installer -pkg \"" & strSavePkgFilePath & "\" -target / -dumplog -verboseR -allowUntrusted -lang ja>> \"" & strLogFilePath & "\" 2>&1") as text |
118 | log strCommandText |
119 | try |
120 | do shell script strCommandText user name strAdminUserName password strAuthPW with administrator privileges |
121 | set boolInstallDone to true as boolean |
122 | log "【5】正常処理" |
123 | on error |
124 | set strCommandText to ("/bin/cat \"" & strLogFilePath & "\"") as text |
125 | try |
126 | set strResponse to (do shell script strCommandText) as text |
127 | end try |
128 | set boolInstallDone to false as boolean |
129 | log "【5】インストール失敗" |
130 | end try |
131 | |
132 | |
133 | ###################################### |
134 | #インストーラーをゴミ箱に |
135 | set listDone to (appFileManager's trashItemAtURL:(ocidDownloadDirPathURL) resultingItemURL:(ocidDownloadDirPathURL) |error| :(reference)) |
136 | if (item 1 of listDone) is true then |
137 | log "【6】 正常処理" |
138 | else if (item 2 of listDone) ≠ (missing value) then |
139 | set strErrorNo to (item 2 of listDone)'s code() as text |
140 | set strDescription to (item 2 of listDone)'s localizedDescription() as text |
141 | log doDialog("【6】でエラーしました\n" & strErrorNo & "\n" & strDescription) |
142 | return "trashItemAtURL エラーしました" |
143 | end if |
144 | if boolInstallDone is false then |
145 | log doDialog("【5】でエラーしました\n" & strResponse & "\n") |
146 | end if |
147 | return |
148 | |
149 | ###################################### |
150 | #ダイアログ |
151 | to doDialog(argMessage) |
152 | tell current application |
153 | set strName to name as text |
154 | end tell |
155 | if strName is "osascript" then |
156 | tell application "Finder" |
157 | activate |
158 | end tell |
159 | else |
160 | tell current application |
161 | activate |
162 | end tell |
163 | end if |
164 | try |
165 | set aliasIconPath to POSIX file "/System/Applications/Mail.app/Contents/Resources/ApplicationIcon.icns" as alias |
166 | set recordResult to (display dialog "メッセージをメールで送ってください" with title "戻り値です" default answer (argMessage as text) buttons {"クリップボードにコピー", "終了", "メール送信"} default button "クリップボードにコピー" cancel button "終了" giving up after 20 with icon aliasIconPath without hidden answer) as record |
167 | on error |
168 | return "エラーしました" |
169 | end try |
170 | if (gave up of recordResult) is true then |
171 | return "時間切れです" |
172 | end if |
173 | ############################## |
174 | #値のコピー |
175 | if button returned of recordResult is "クリップボードにコピー" then |
176 | try |
177 | set strText to text returned of recordResult as text |
178 | ####ペーストボード宣言 |
179 | set appPasteboard to refMe's NSPasteboard's generalPasteboard() |
180 | set ocidText to (refMe's NSString's stringWithString:(strText)) |
181 | appPasteboard's clearContents() |
182 | appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString) |
183 | on error |
184 | tell application "Finder" |
185 | set the clipboard to strText as text |
186 | end tell |
187 | end try |
188 | end if |
189 | ############################## |
190 | #メール送信 |
191 | if button returned of recordResult is "メール送信" then |
192 | set strText to text returned of recordResult as text |
193 | ###コンポーネント初期化 |
194 | set ocidComponents to refMe's NSURLComponents's alloc()'s init() |
195 | ###スキーム mailtoを追加 |
196 | ocidComponents's setScheme:("mailto") |
197 | ###パスを追加(setHostじゃないよ) |
198 | ocidComponents's setPath:(strAdminEmail) |
199 | #クエリーアイテム |
200 | set ocidQueryItems to refMe's NSMutableArray's alloc()'s initWithCapacity:(0) |
201 | set ocidQueryItem to refMe's NSURLQueryItem's alloc()'s initWithName:("subject") value:("【処理終了】処理終了自動送信") |
202 | ocidQueryItems's addObject:(ocidQueryItem) |
203 | set ocidQueryItem to refMe's NSURLQueryItem's alloc()'s initWithName:("body") value:(strText) |
204 | ocidQueryItems's addObject:(ocidQueryItem) |
205 | #コンポーネントに追加 |
206 | ocidComponents's setQueryItems:(ocidQueryItems) |
207 | #URLを再定義 |
208 | set ocidURL to ocidComponents's |URL| |
209 | #URLを開く(デフォルトのメーラで起動) |
210 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
211 | set boolDone to appSharedWorkspace's openURL:(ocidURL) |
212 | if boolDone is true then |
213 | log "正常処理" |
214 | return true |
215 | else if boolDone is false then |
216 | log "エラーしました" |
217 | return false |
218 | end if |
219 | end if |
220 | end doDialog |
221 | |
222 | |
AppleScriptで生成しました |
| 固定リンク
行番号 | ソース |
---|---|
001 | #! /usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | #com.cocolog-nifty.quicktimer.icefloe |
004 | # 【注意事項】必ず 『実行専用』の『アプリケーション』にしてください |
005 | #管理者パスワードが平文で記述される事になりますので |
006 | #セキュリティには留意ください |
007 | #また |
008 | #厳密にはログに管理者パスワードが平文で流れますので |
009 | #使用はインハウス等に限定された方がいいかもしれません |
010 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
011 | use AppleScript version "2.8" |
012 | use framework "Foundation" |
013 | use framework "AppKit" |
014 | use scripting additions |
015 | |
016 | property refMe : a reference to current application |
017 | |
018 | ###################################### |
019 | #設定項目 |
020 | #インストールするパッケージのURL(DMGじゃダメよ) |
021 | set strPkgURL to ("https://ardownload3.adobe.com/pub/adobe/acrobat/mac/AcrobatDC/2400220854/AcrobatSCADC2400220854_MUI.pkg") as text |
022 | |
023 | |
024 | #管理者ユーザー名(ショート) |
025 | set strAdminUserName to ("admin") as text |
026 | #管理者パスワード |
027 | set strAuthPW to ("管理者パスワードをここに") as text |
028 | #報告メールの送信先 |
029 | property strAdminEmail : ("foo@hoge.com") as text |
030 | |
031 | |
032 | ###################################### |
033 | #保存先 ダウンロードフォルダ ocidDownloadDirPathURL |
034 | set appFileManager to refMe's NSFileManager's defaultManager() |
035 | set ocidTempDirURL to appFileManager's temporaryDirectory() |
036 | set ocidUUID to refMe's NSUUID's alloc()'s init() |
037 | set ocidUUIDString to ocidUUID's UUIDString |
038 | set ocidDownloadDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:(true) |
039 | #フォルダを作る これだけアクセス権777 |
040 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0 |
041 | ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions) |
042 | set listDone to appFileManager's createDirectoryAtURL:(ocidDownloadDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error| :(reference) |
043 | if (item 1 of listDone) is true then |
044 | log "【1】正常処理" |
045 | set ocidLogFilePathURL to ocidDownloadDirPathURL's URLByAppendingPathComponent:("_このフォルダは削除しても大丈夫です.txt") isDirectory:(false) |
046 | set ocidLogStr to refMe's NSString's stringWithString:("このフォルダは削除しても大丈夫です") |
047 | set listDone to ocidLogStr's writeToURL:(ocidLogFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error| :(reference) |
048 | if (item 1 of listDone) is true then |
049 | set strLogFilePath to (ocidLogFilePathURL's |path|()) as text |
050 | log "【2】正常処理" |
051 | else if (item 2 of listDone) ≠ (missing value) then |
052 | set strErrorNo to (item 2 of listDone)'s code() as text |
053 | set strDescription to (item 2 of listDone)'s localizedDescription() as text |
054 | log doDialog("【2】でエラーしました\n" & strErrorNo & "\n" & strDescription) |
055 | return "エラーしました" |
056 | end if |
057 | |
058 | else if (item 2 of listDone) ≠ (missing value) then |
059 | set strErrorNo to (item 2 of listDone)'s code() as text |
060 | set strDescription to (item 2 of listDone)'s localizedDescription() as text |
061 | log doDialog("【1】でエラーしました\n" & strErrorNo & "\n" & strDescription) |
062 | return "エラーしました" |
063 | end if |
064 | ###################################### |
065 | #ダウンロード 本処理 |
066 | set ocidURLString to refMe's NSString's stringWithString:(strPkgURL) |
067 | set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidURLString) |
068 | set strURL to ocidURL's absoluteString() as text |
069 | set ocidFileName to ocidURL's lastPathComponent() |
070 | set strFileName to ocidFileName as text |
071 | #保存パス |
072 | set ocidSavePkgFilePathURL to ocidDownloadDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:(false) |
073 | set strSavePkgFilePath to (ocidSavePkgFilePathURL's |path|()) as text |
074 | #NSDATA |
075 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
076 | set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidURL) options:(ocidOption) |error| :(reference) |
077 | if (item 2 of listResponse) = (missing value) then |
078 | log "【3】正常処理" |
079 | set ocidReadData to (item 1 of listResponse) |
080 | #writeToURL |
081 | set ocidOption to (refMe's NSDataWritingAtomic) |
082 | set listDone to ocidReadData's writeToURL:(ocidSavePkgFilePathURL) options:(ocidOption) |error| :(reference) |
083 | if (item 1 of listDone) is true then |
084 | log "【4】正常処理" |
085 | else if (item 2 of listDone) ≠ (missing value) then |
086 | set strErrorNo to (item 2 of listDone)'s code() as text |
087 | set strDescription to (item 2 of listDone)'s localizedDescription() as text |
088 | log doDialog("【4】でエラーしました\n" & strErrorNo & "\n" & strDescription) |
089 | return "エラーしました" |
090 | end if |
091 | else if (item 2 of listResponse) ≠ (missing value) then |
092 | log "initWithContentsOfURL エラーしました CULRを試します" |
093 | #CULR |
094 | set strCommandText to ("/usr/bin/curl -v -L -o \"" & strSavePkgFilePath & "\" \"" & strURL & "\" --connect-timeout 20 >> \"" & strLogFilePath & "\" 2>>&1") as text |
095 | log strCommandText |
096 | try |
097 | do shell script strCommandText |
098 | on error |
099 | set strErrorNo to (item 2 of listResponse)'s code() as text |
100 | set strDescription to (item 2 of listResponse)'s localizedDescription() as text |
101 | log doDialog("【3】でエラーしました\n" & strErrorNo & "\n" & strDescription) |
102 | return "CURL エラーしました" |
103 | end try |
104 | end if |
105 | ###################################### |
106 | #インストール本処理 |
107 | set strCommandText to ("/usr/bin/sudo /usr/sbin/installer -pkg \"" & strSavePkgFilePath & "\" -target / -dumplog -verboseR -allowUntrusted -lang ja>> \"" & strLogFilePath & "\" 2>&1") as text |
108 | log strCommandText |
109 | try |
110 | do shell script strCommandText user name strAdminUserName password strAuthPW with administrator privileges |
111 | set boolInstallDone to true as boolean |
112 | log "【5】正常処理" |
113 | on error |
114 | set strCommandText to ("/bin/cat \"" & strLogFilePath & "\"") as text |
115 | try |
116 | set strResponse to (do shell script strCommandText) as text |
117 | end try |
118 | set boolInstallDone to false as boolean |
119 | log "【5】インストール失敗" |
120 | end try |
121 | |
122 | |
123 | ###################################### |
124 | #インストーラーをゴミ箱に |
125 | set listDone to (appFileManager's trashItemAtURL:(ocidDownloadDirPathURL) resultingItemURL:(ocidDownloadDirPathURL) |error| :(reference)) |
126 | if (item 1 of listDone) is true then |
127 | log "【6】 正常処理" |
128 | else if (item 2 of listDone) ≠ (missing value) then |
129 | set strErrorNo to (item 2 of listDone)'s code() as text |
130 | set strDescription to (item 2 of listDone)'s localizedDescription() as text |
131 | log doDialog("【6】でエラーしました\n" & strErrorNo & "\n" & strDescription) |
132 | return "trashItemAtURL エラーしました" |
133 | end if |
134 | if boolInstallDone is false then |
135 | log doDialog("【5】でエラーしました\n" & strResponse & "\n") |
136 | end if |
137 | return |
138 | |
139 | ###################################### |
140 | #ダイアログ |
141 | to doDialog(argMessage) |
142 | tell current application |
143 | set strName to name as text |
144 | end tell |
145 | if strName is "osascript" then |
146 | tell application "Finder" |
147 | activate |
148 | end tell |
149 | else |
150 | tell current application |
151 | activate |
152 | end tell |
153 | end if |
154 | try |
155 | set aliasIconPath to POSIX file "/System/Applications/Mail.app/Contents/Resources/ApplicationIcon.icns" as alias |
156 | set recordResult to (display dialog "メッセージをメールで送ってください" with title "戻り値です" default answer (argMessage as text) buttons {"クリップボードにコピー", "終了", "メール送信"} default button "クリップボードにコピー" cancel button "終了" giving up after 20 with icon aliasIconPath without hidden answer) as record |
157 | on error |
158 | return "エラーしました" |
159 | end try |
160 | if (gave up of recordResult) is true then |
161 | return "時間切れです" |
162 | end if |
163 | ############################## |
164 | #値のコピー |
165 | if button returned of recordResult is "クリップボードにコピー" then |
166 | try |
167 | set strText to text returned of recordResult as text |
168 | ####ペーストボード宣言 |
169 | set appPasteboard to refMe's NSPasteboard's generalPasteboard() |
170 | set ocidText to (refMe's NSString's stringWithString:(strText)) |
171 | appPasteboard's clearContents() |
172 | appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString) |
173 | on error |
174 | tell application "Finder" |
175 | set the clipboard to strText as text |
176 | end tell |
177 | end try |
178 | end if |
179 | ############################## |
180 | #メール送信 |
181 | if button returned of recordResult is "メール送信" then |
182 | set strText to text returned of recordResult as text |
183 | ###コンポーネント初期化 |
184 | set ocidComponents to refMe's NSURLComponents's alloc()'s init() |
185 | ###スキーム mailtoを追加 |
186 | ocidComponents's setScheme:("mailto") |
187 | ###パスを追加(setHostじゃないよ) |
188 | ocidComponents's setPath:(strAdminEmail) |
189 | #クエリーアイテム |
190 | set ocidQueryItems to refMe's NSMutableArray's alloc()'s initWithCapacity:(0) |
191 | set ocidQueryItem to refMe's NSURLQueryItem's alloc()'s initWithName:("subject") value:("【処理終了】処理終了自動送信") |
192 | ocidQueryItems's addObject:(ocidQueryItem) |
193 | set ocidQueryItem to refMe's NSURLQueryItem's alloc()'s initWithName:("body") value:(strText) |
194 | ocidQueryItems's addObject:(ocidQueryItem) |
195 | #コンポーネントに追加 |
196 | ocidComponents's setQueryItems:(ocidQueryItems) |
197 | #URLを再定義 |
198 | set ocidURL to ocidComponents's |URL| |
199 | #URLを開く(デフォルトのメーラで起動) |
200 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
201 | set boolDone to appSharedWorkspace's openURL:(ocidURL) |
202 | if boolDone is true then |
203 | log "正常処理" |
204 | return true |
205 | else if boolDone is false then |
206 | log "エラーしました" |
207 | return false |
208 | end if |
209 | end if |
210 | end doDialog |
211 | |
212 | |
AppleScriptで生成しました |
| 固定リンク
行番号 | ソース |
---|---|
001 | #!/bin/bash |
002 | #com.cocolog-nifty.quicktimer.icefloe |
003 | # /installerHistory.sh の改造版 |
004 | # https://github.com/BigMacAdmin/macOS-Stuff/blob/main/installerHistory.sh |
005 | ################################################# |
006 | USER_WHOAMI=$(/usr/bin/whoami) |
007 | /bin/echo "実行ユーザー(whoami): $USER_WHOAMI" |
008 | ###実行しているユーザー名 |
009 | CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }') |
010 | /bin/echo "コンソールユーザー(scutil): $CONSOLE_USER" |
011 | ###実行しているユーザー名 |
012 | HOME_USER=$(/bin/echo "$HOME" | /usr/bin/awk -F'/' '{print $NF}') |
013 | /bin/echo "実行ユーザー(HOME): $HOME_USER" |
014 | ###logname |
015 | LOGIN_NAME=$(/usr/bin/logname) |
016 | /bin/echo "ログイン名(logname): $LOGIN_NAME" |
017 | ###UID |
018 | USER_NAME=$(/usr/bin/id -un) |
019 | /bin/echo "ユーザー名(id): $USER_NAME" |
020 | ###STAT |
021 | STAT_USR=$(/usr/bin/stat -f%Su /dev/console) |
022 | /bin/echo "STAT_USR(console): $STAT_USR" |
023 | |
024 | ######################################## |
025 | ##保存先 |
026 | STR_SAVE_DIR_PATH="/Users/${STAT_USR}/Documents/Apple/system_profiler" |
027 | /bin/mkdir -p "$STR_SAVE_DIR_PATH" |
028 | PLIST_GRN="<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><array><string>グリーン</string></array></plist>" |
029 | /usr/bin/xattr -w com.apple.metadata:_kMDItemUserTags "$PLIST_GRN" "$STR_SAVE_DIR_PATH" |
030 | STR_DIR_FILE_PATH="$STR_SAVE_DIR_PATH/_このフォルダは削除しても大丈夫です.txt" |
031 | /usr/bin/touch "$STR_DIR_FILE_PATH" |
032 | #保存ファイル |
033 | STR_PLIST_FILE_PATH="$STR_SAVE_DIR_PATH/SPInstallHistoryDataType.plist" |
034 | STR_TEXT_FILE_PATH="$STR_SAVE_DIR_PATH/SPInstallHistoryDataType.txt" |
035 | #データ収集 |
036 | /usr/sbin/system_profiler SPInstallHistoryDataType -xml -detailLevel mini >"$STR_PLIST_FILE_PATH" |
037 | #数数えて |
038 | NUM_CNT_DICT=$(/usr/libexec/PlistBuddy -c "Print :0:_items:" "$STR_PLIST_FILE_PATH" | grep -o "Dict" | wc -l) |
039 | STR_NOW_DATE=$(/bin/date "+%Y%m%d" ) |
040 | /bin/echo "【$STR_NOW_DATE 作成】インストール履歴は $NUM_CNT_DICT 件です" >"$STR_TEXT_FILE_PATH" |
041 | |
042 | #履歴権数だけ繰り返し |
043 | for ((i = 0; i < NUM_CNT_DICT; i++)); do |
044 | STR_DATE=$(/usr/libexec/PlistBuddy -c "Print :0:_items:$i:install_date" "$STR_PLIST_FILE_PATH") |
045 | FORMATTED_DATE=$(/bin/date -j -f "%a %b %d %T %Z %Y" "$STR_DATE" "+%Y%m%d") |
046 | STR_APP_NAME=$(/usr/libexec/PlistBuddy -c "Print :0:_items:$i:_name" "$STR_PLIST_FILE_PATH") |
047 | /bin/echo "$FORMATTED_DATE : $STR_APP_NAME" >>"$STR_TEXT_FILE_PATH" |
048 | done |
049 | #終わったら開く |
050 | /usr/bin/open -b com.apple.TextEdit "$STR_TEXT_FILE_PATH" |
051 | |
052 | exit 0 |
AppleScriptで生成しました |
| 固定リンク
| 固定リンク
| 固定リンク
| 固定リンク
Accessibility Acrobat Acrobat 2020 Acrobat AddOn Acrobat Annotation Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat JS Acrobat Manifest Acrobat Menu Acrobat Open Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat python Acrobat Reader Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin Support Admin System Information Admin Tools Admin Users Admin Volumes Adobe Adobe FDKO Adobe RemoteUpdateManager AppKit Apple AppleScript AppleScript do shell script AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript System Events AppleScript System Events Plist AppleScript Video Applications AppStore Archive Attributes Automator BackUp Barcode Barcode QR Barcode QR Decode Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome CIImage CityCode CloudStorage Color com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Device Diff Disk Dock DropBox Droplet eMail Encode % Encode Decode Encode UTF8 Error EXIFData ffmpeg File Finder Firefox Folder FolderAction Fonts GIF github Guide HTML HTML Entity Icon Illustrator Image Events Image2PDF ImageOptim iPhone iWork Javascript Jedit Json Label Leading Zero List locationd LRC lsappinfo LSSharedFileList m3u8 Mail MakePDF Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Mouse Music NetWork Notes NSArray NSArray Sort NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSColor NSColorList NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSPrintOperation NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth OneDrive PDF PDFAnnotation PDFAnnotationWidget PDFContext PDFDisplayBox PDFDocumentPermissions PDFImageRep PDFKit PDFnUP PDFOutline perl Photoshop PlistBuddy pluginkit postalcode PostScript prefPane Preview Python QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver SF Symbols character id SF Symbols Entity sips Skype Slack Sound Spotlight sqlite SRT StandardAdditions Swift System Settings TCC TemporaryItems Terminal Text Text CSV Text MD Text TSV TextEdit Tools Translate Trash Twitter Typography UI Unit Conversion UTType valueForKeyPath Video VisionKit Visual Studio Code VMware Fusion Wacom webarchive webp Wifi Windows XML XML EPUB XML OPML XML Plist XML RSS XML savedSearch XML SVG XML TTML XML webloc XML XMP YouTube zoom