AppleScript Archive

[bash]UnarchiverDMGインストール


#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe

##################################
USER_WHOAMI=$(/usr/bin/whoami)
/bin/echo "実行ユーザー(whoami): $USER_WHOAMI"
###実行しているユーザー名
CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }')
/bin/echo "コンソールユーザー(scutil): $CONSOLE_USER"
###実行しているユーザー名
HOME_USER=$(/bin/echo "$HOME" | /usr/bin/awk -F'/' '{print $NF}')
/bin/echo "実行ユーザー(HOME): $HOME_USER"
###logname
LOGIN_NAME=$(/usr/bin/logname)
/bin/echo "ログイン名(logname): $LOGIN_NAME"
###UID
USER_NAME=$(/usr/bin/id -un)
/bin/echo "ユーザー名(id): $USER_NAME"
###STAT
STAT_USR=$(/usr/bin/stat -f%Su /dev/console)
/bin/echo "STAT_USR(console): $STAT_USR"
##################################
/bin/echo "インストール先確保" $HOME/Applications/Utilities
/bin/mkdir -p $HOME/Applications/Utilities
/bin/chmod 700 $HOME/Applications
/bin/chmod 755 $HOME/Applications/Utilities
/usr/bin/touch $HOME/Applications/.localized
/usr/bin/touch $HOME/Applications/Utilities/.localized
##################################
LIST_APPNAME=("unar" "Unarchiver")
for ITEM_APPNAME in "${LIST_APPNAME[@]}"; do
STR_PNO=$(/usr/bin/pgrep -f "$ITEM_APPNAME")
/bin/kill -9 "$STR_PNO"
done
##################################
STR_URL="https://dl.devmate.com/com.macpaw.site.theunarchiver/TheUnarchiver.dmg"
##ダウンロード先
STR_TMPDIRPATH=$(/usr/bin/mktemp -d)
/bin/chmod 777 "$STR_TMPDIRPATH"
/bin/echo "ダウンロード開始:" "$STR_TMPDIRPATH"
##生存確認
/usr/bin/curl -s --head "$STR_URL" >/dev/null
if [ $? -ne 0 ]; then
/bin/echo "エラー:URLの生存確認で失敗しました"
exit 1
fi
###リダイレクト先のURLを取得
STR_REDIRECT_URL=$(/usr/bin/curl -s -L -I -o /dev/null -w '%{url_effective}' "$STR_URL")
if [ $? -ne 0 ]; then
/bin/echo "エラー:リダイレクトの取得に失敗しました"
exit 1
fi
###ファイル名を取得
STR_FILE_NAME=$(/usr/bin/basename "$STR_REDIRECT_URL")
/bin/echo "ファイル名:$PKG_FILE_NAME"
###ダウンロード
/usr/bin/curl -L --retry 3 --retry-connrefused --retry-delay 3 -o "$STR_TMPDIRPATH/$STR_FILE_NAME" "$STR_URL"
if [ $? -ne 0 ]; then
/bin/echo "エラー:ダウンロードに失敗しました"
exit 1
fi
##################################
STR_DMG_PATH="$STR_TMPDIRPATH/$STR_FILE_NAME"
/usr/bin/hdiutil attach "$STR_DMG_PATH" -noverify -nobrowse -noautoopen
if [ $? -ne 0 ]; then
/bin/echo "エラー:ディスクのマウントで失敗しました"
exit 1
fi
##################################
STR_DIST_PATH="$HOME/Applications/Utilities/The Unarchiver.app/"
if [ -d "$STR_DIST_PATH" ]; then
/bin/echo "ファイルが存在します"
STR_TRASH_DIR=$(/usr/bin/mktemp -d "$HOME/.Trash/Unarchiver.XXXXXXXX")
/bin/chmod 777 "$STR_TRASH_DIR"
/bin/mv -f "$STR_DIST_PATH" "$STR_TRASH_DIR"
/bin/echo "古いファイルをゴミ箱に入れました"
fi
##################################
STR_ORG_PATH="/Volumes/The Unarchiver/The Unarchiver.app"
/usr/bin/ditto "$STR_ORG_PATH" "$STR_DIST_PATH"
if [ $? -ne 0 ]; then
/usr/bin/hdiutil detach "/Volumes/The Unarchiver" -force
/bin/echo "エラー:ファイルのコピーで失敗しました"
exit 1
fi
##################################
/usr/bin/hdiutil detach "/Volumes/The Unarchiver" -force
if [ $? -ne 0 ]; then
/usr/bin/hdiutil detach "/Volumes/The Unarchiver 1" -force
/usr/bin/hdiutil detach "/Volumes/The Unarchiver 2" -force
/bin/echo "エラー:ディスクのアンマウントに失敗しました"
exit 1
fi
##################################
LIST_BUNDLEID=("cx.c3.theunarchiver" "com.macpaw.site.theunarchiver")
for ITEM_BUNDLEID in "${LIST_BUNDLEID[@]}"; do
/bin/echo "$ITEM_BUNDLEID"
/usr/bin/defaults write "$ITEM_BUNDLEID" createFolder -integer 2
/usr/bin/defaults write "$ITEM_BUNDLEID" extractionDestination -integer 1
/usr/bin/defaults write "$ITEM_BUNDLEID" folderModifiedDate -integer 2
/usr/bin/defaults write "$ITEM_BUNDLEID" LaunchCount -integer 0
/usr/bin/defaults write "$ITEM_BUNDLEID" filenameEncoding -integer 8
/usr/bin/defaults write "$ITEM_BUNDLEID" TUConfigInformationBannerViewedCount -integer 0
/usr/bin/defaults write "$ITEM_BUNDLEID" OnboardingUserViewedWelcomeSlide -bool true
/usr/bin/defaults write "$ITEM_BUNDLEID" SUEnableAutomaticChecks -bool true
/usr/bin/defaults write "$ITEM_BUNDLEID" userAgreedToNewTOSAndPrivacy -bool true
/usr/bin/defaults write "$ITEM_BUNDLEID" isFreshInstall -bool true
/usr/bin/defaults write "$ITEM_BUNDLEID" TUConfigInformationBannerOpened -bool true
/usr/bin/defaults write "$ITEM_BUNDLEID" deleteExtractedArchive -bool true
/usr/bin/defaults write "$ITEM_BUNDLEID" TUConfigInformationBannerOpened -bool true
/bin/echo "基本設定を行いました"
done

/usr/bin/killall cfprefsd

/bin/echo "終了しました"
exit 0


|

[bash]UnarchiverCLIインストール


#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe

##################################
USER_WHOAMI=$(/usr/bin/whoami)
/bin/echo "実行ユーザー(whoami): $USER_WHOAMI"
###実行しているユーザー名
CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }')
/bin/echo "コンソールユーザー(scutil): $CONSOLE_USER"
###実行しているユーザー名
HOME_USER=$(/bin/echo "$HOME" | /usr/bin/awk -F'/' '{print $NF}')
/bin/echo "実行ユーザー(HOME): $HOME_USER"
###logname
LOGIN_NAME=$(/usr/bin/logname)
/bin/echo "ログイン名(logname): $LOGIN_NAME"
###UID
USER_NAME=$(/usr/bin/id -un)
/bin/echo "ユーザー名(id): $USER_NAME"
###STAT
STAT_USR=$(/usr/bin/stat -f%Su /dev/console)
/bin/echo "STAT_USR(console): $STAT_USR"

##################################
STR_PNO=$(/usr/bin/pgrep -f "unar")
/bin/kill -9 "$STR_PNO"

##################################
STR_URL="https://cdn.theunarchiver.com/downloads/unarMac.zip"
##ダウンロード先
STR_TMPDIRPATH=$(/usr/bin/mktemp -d)
/bin/chmod 777 "$STR_TMPDIRPATH"
/bin/echo "ダウンロード開始:" "$STR_TMPDIRPATH"
##生存確認
/usr/bin/curl -s --head "$STR_URL" >/dev/null
if [ $? -ne 0 ]; then
/bin/echo "エラー:URLの生存確認で失敗しました"
exit 1
fi
###リダイレクト先のURLを取得
STR_REDIRECT_URL=$(/usr/bin/curl -s -L -I -o /dev/null -w '%{url_effective}' "$STR_URL")
if [ $? -ne 0 ]; then
/bin/echo "エラー:リダイレクトの取得に失敗しました"
exit 1
fi
###ファイル名を取得
STR_FILE_NAME=$(/usr/bin/basename "$STR_REDIRECT_URL")
/bin/echo "ファイル名:$PKG_FILE_NAME"
###ダウンロード
/usr/bin/curl -L --retry 3 --retry-connrefused --retry-delay 3 -o "$STR_TMPDIRPATH/$STR_FILE_NAME" "$STR_URL"
if [ $? -ne 0 ]; then
/bin/echo "エラー:ダウンロードに失敗しました"
exit 1
fi
##################################
STR_DIST_PATH="$HOME/bin/unarMac/"
if [ -d "$STR_DIST_PATH" ]; then
/bin/echo "ファイルが存在します"
STR_TRASH_DIR=$(/usr/bin/mktemp -d "$HOME/.Trash/Unarchiver.XXXXXXXX")
/bin/chmod 777 "$STR_TRASH_DIR"
/bin/mv -f "$STR_DIST_PATH" "$STR_TRASH_DIR"
/bin/echo "古いファイルをゴミ箱に入れました"
fi
##################################
/bin/echo "インストール先確保" $HOME/bin/unarMac
/bin/mkdir -p $HOME/bin/unarMac
/bin/chmod 700 $HOME/bin
/bin/chmod 755 $HOME/bin/unarMac
##################################
/usr/bin/ditto -xk "$STR_TMPDIRPATH/$STR_FILE_NAME" "$STR_DIST_PATH"
if [ $? -ne 0 ]; then
/bin/echo "エラー:ファイルのコピーで失敗しました"
exit 1
fi
/bin/echo "終了しました"
exit 0


|

圧縮・解凍(2024)

圧縮解凍
圧縮解凍:Keka
https://www.keka.io/ja/
解凍:The Unarchiver
https://theunarchiver.com
圧縮解凍:Archive Utility
/System/Library/CoreServices/Applications/Archive Utility.app
Archive Utility 関連詰め合わせ
https://quicktimer.cocolog-nifty.com/icefloe/files/archive20utility.zip
圧縮解凍:ZIPANG[LINK]
ミラー
zipang.zip
zipangfull.zip



拡張子:zip
/usr/bin/zip
/usr/bin/unzip
/usr/bin/zipgrep
/usr/bin/zipinfo
/usr/bin/zipnote
/usr/bin/zipsplit
/usr/bin/zipdetails
/usr/bin/zipcloak
パスワード付きZip圧縮
https://quicktimer.cocolog-nifty.com/icefloe/2024/03/post-5953ab.html
[ドロップレット]EPUB用zip圧縮(半角スペース対応)
https://quicktimer.cocolog-nifty.com/icefloe/2023/11/post-c6729c.html


拡張子:tar gz bz2 xz Z
圧縮解凍:/usr/bin/tar →/usr/bin/bsdtar


拡張子:.gz
https://quicktimer.cocolog-nifty.com/icefloe/2024/01/post-a8b24c.html
圧縮:/usr/bin/gzip
解凍 :/usr/bin/gunzip →/usr/bin/zcat
出力:/usr/bin/zcat


拡張子:bz2
https://quicktimer.cocolog-nifty.com/icefloe/2024/02/post-cd5c00.html
圧縮:/usr/bin/bzip2
解凍:/usr/bin/bunzip2
出力:/usr/bin/bzcat


拡張子:Z
圧縮解凍:/usr/bin/compress


その他インストールが必要なコマンドラインツール
解凍:unar Unarchiverのコマンドラインツール
https://github.com/ashang/unar
バイナリーはこちらから
https://theunarchiver.com/command-line


圧縮解凍:7-Zip
https://7-zip.org/
Mac版はこちらから
https://www.7-zip.org/download.html
[AppleScript]7zzインストール
https://quicktimer.cocolog-nifty.com/icefloe/2024/01/post-01fee7.html
[7zz]パスワード付きで圧縮する
https://quicktimer.cocolog-nifty.com/icefloe/2023/05/post-3dbc87.html

|

拡張子:bz2

拡張子:bz2
圧縮:/usr/bin/bzip2
解凍:/usr/bin/bunzip2
出力:/usr/bin/bzcat



-h --help print this message
-d --decompress 解凍:force decompression
-z --compress 圧縮:force compression
-k --keep 入力ファイルを削除しないkeep (don't delete) input files
-f --force 出力ファイル上書き:overwrite existing output files
-t --test test compressed file integrity
-c --stdout 標準出力:output to standard out
-q --quiet ログ出力しない:suppress noncritical error messages
-v --verbose メッセージ出力:be verbose (a 2nd -v gives more)
-L --license display software version & license
-V --version display software version & license
-s --small メモリー消費を少なく:use less memory (at most 2500k)
-1 .. -9 set block size to 100k .. 900k
--fast alias for -1
--best alias for -9
数値が少ないと圧縮率が低く 高速
数値が多いと圧縮率が高く 低速



#!/bin/bash

# 入力ファイル/some/inputfileは削除される
/usr/bin/bzip2 /some/inputfile

#入力ファイルを残す
/usr/bin/bzip2 --keep /some/inputfile
/usr/bin/bzip2 -k /some/inputfile

#圧縮ファイル名を指定する オリジナルを残す
/usr/bin/bzip2 --keep /some/inputfile --stdout > /some/inputfile.bz2
/usr/bin/bzip2 -k /some/inputfile -c > /some/inputfile.bz2

|

パスワード付きZip圧縮


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# ドロップレットとしても使えます
# ファイル>書き出し>アプリケーション で書き出してください
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.6"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application
property strBinPath : "/usr/bin/zip"

on run
  set appFileManager to refMe's NSFileManager's defaultManager()
  #############################
  ###ダイアログ
  tell current application
    set strName to name as text
  end tell
  ###スクリプトメニューから実行したら
  if strName is "osascript" then
    tell application "Finder" to activate
  else
    tell current application to activate
  end if
  ###デフォルトロケーション
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
  set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
  set listUTI to {"public.item"}
  set strMes to ("ファイルを選んでください") as text
  set strPrompt to ("ファイルを選んでください") as text
  try
    set listDropObject to (choose file strMes with prompt strPrompt default location aliasDefaultLocation of type listUTI with invisibles, multiple selections allowed and showing package contents) as list
  on error
return "エラーしました"
  end try
  
open listDropObject
end run


on open listDropObject
  ###NSFileManager初期化
  set appFileManager to refMe's NSFileManager's defaultManager()
  ###Path to me
  tell application "Finder"
    set aliasPathToMe to (path to me) as alias
  end tell
  ###ドロップの数だけ繰返し
  repeat with itemDropObject in listDropObject
    #################################
    ###処理する判定
    set boolChkAliasPath to true as boolean
    try
      tell application "Finder"
        set strKind to (kind of itemDropObject) as text
      end tell
    on error
log "kindを取得できないファイルは処理しない"
      set boolChkAliasPath to false as boolean
    end try
    if strKind is "アプリケーション" then
log "アプリケーションは処理しない"
      set boolChkAliasPath to false as boolean
    else if strKind is "ボリューム" then
log "ボリュームは処理しない"
      set boolChkAliasPath to false as boolean
    else if strKind is "エイリアス" then
log "エイリアスは処理しない"
      set boolChkAliasPath to false as boolean
    end if
    #################################
    ###trueの場合のみ圧縮処理する
    if boolChkAliasPath is true then
      ########################################
      #####パスワード生成 UUIDを利用
      ###生成したUUIDからハイフンを取り除く
      set ocidUUIDString to (refMe's NSMutableString's alloc()'s initWithCapacity:0)
      set ocidConcreteUUID to refMe's NSUUID's UUID()
(ocidUUIDString's setString:(ocidConcreteUUID's UUIDString()))
      set ocidUUIDRange to (ocidUUIDString's rangeOfString:ocidUUIDString)
(ocidUUIDString's replaceOccurrencesOfString:("-") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidUUIDRange)
      set strOwnerPassword to ocidUUIDString as text
      ########################################
      #####パス
      set strFilePath to (POSIX path of itemDropObject) as text
      set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
      set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
      set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false)
      set ocidDirName to ocidFilePathURL's lastPathComponent()
      set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
      set strDirName to ocidDirName as text
      set strMakeDirName to (strDirName & "_圧縮済")
      set ocidBaseFilePathURL to (ocidContainerDirPathURL's URLByAppendingPathComponent:strMakeDirName)
      #####################
      ###フォルダを作る
      set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions))
      set listBoolMakeDir to (appFileManager's createDirectoryAtURL:(ocidBaseFilePathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference))
      #####################
      ###zipPath
      set ocidDirFilePathURL to (ocidBaseFilePathURL's URLByAppendingPathComponent:(ocidDirName))
      set ocidZipFilePathURL to (ocidDirFilePathURL's URLByAppendingPathExtension:"zip")
      set strZipFilePathURL to ocidZipFilePathURL's |path|() as text
      ########################################
      #####パスワード生成 UUIDを利用
      set strTextFileName to strDirName & ".pw.txt"
      set ocidTextFilePathURL to (ocidBaseFilePathURL's URLByAppendingPathComponent:strTextFileName)
      ###テキスト
      set strTextFile to "先にお送りしました圧縮ファイル\n『" & strDirName & "』の\n解凍パスワードをお知らせします\n\n" & strOwnerPassword & "\n\n解凍出来ない等ありましたらお知らせください。\n(パスワードをコピー&ペーストする際に\n改行やスペースが入らないように留意ください)\n" as text
      set ocidPWString to (refMe's NSString's stringWithString:strTextFile)
      set ocidUUIDData to (ocidPWString's dataUsingEncoding:(refMe's NSUTF8StringEncoding))
      #####パスワードを書いたテキストファイルを保存
      set boolResults to (ocidUUIDData's writeToURL:ocidTextFilePathURL atomically:true)
      ########################################
      #####コマンド実行
      ###パス情報を残す
      ##set strCommandText to ("\"" & strBinPath & "\" -X -e -P " & strOwnerPassword & " \"" & strZipFilePathURL & "\" -r \"" & strFilePath & "\"")
      ###パス情報を残さない
      set strCommandText to ("\"" & strBinPath & "\" -j -X -e -P " & strOwnerPassword & " \"" & strZipFilePathURL & "\" -r \"" & strFilePath & "\"")
log strCommandText
do shell script strCommandText
    end if
  end repeat
return "処理終了"
end open



|

拡張子:gz

拡張子:bz2
圧縮:/usr/bin/gzip
解凍 :/usr/bin/gunzip →/usr/bin/zcat
出力:/usr/bin/zcat



-h --help print this message
-d --decompress 解凍:force decompression
-z --compress 圧縮:force compression
-k --keep 入力ファイルを削除しないkeep (don't delete) input files
-f --force 出力ファイル上書き:overwrite existing output files
-t --test test compressed file integrity
-c --stdout 標準出力:output to standard out
-q --quiet ログ出力しない:suppress noncritical error messages
-v --verbose メッセージ出力:be verbose (a 2nd -v gives more)
-L --license display software version & license
-V --version display software version & license
-s --small メモリー消費を少なく:use less memory (at most 2500k)
-1 .. -9 set block size to 100k .. 900k
--fast alias for -1
--best alias for -9
数値が少ないと圧縮率が低く 高速
数値が多いと圧縮率が高く 低速



#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe

# 入力ファイル/some/inputfileは削除される
/usr/bin/gzip /some/inputfile

#入力ファイルを残す
/usr/bin/gzip --keep /some/inputfile
/usr/bin/gzip -k /some/inputfile

#圧縮ファイル名を指定する オリジナルを残す
/usr/bin/gzip -keep /some/inputfile -c > /some/inputfile.gz
/usr/bin/gzip -k /some/inputfile -c > /some/inputfile.gz

exit 0

|

[AppleScript]7zzインストール


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
# 7zz を /Users/実行したユーザー名/bin/7zipにインストールします
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

set strURL to "https://sourceforge.net/projects/sevenzip/rss" as text


################################################
###### RSSデータ保存
################################################
###ディレクトリ
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidTempDirURL to appFileManager's temporaryDirectory()
set ocidUUID to refMe's NSUUID's alloc()'s init()
set ocidUUIDString to ocidUUID's UUIDString
set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
###パス
set strFileName to "feed.xml" as text
set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
set strSaveFilePath to ocidSaveFilePathURL's |path|() as text

set strCommandText to ("/usr/bin/curl \"" & strURL & "\" -o \"" & strSaveFilePath & "\"")
do shell script strCommandText
################################################
###### データ読み込み
################################################
set ocidOption to (refMe's NSXMLDocumentTidyXML)
set listReadXML to refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidSaveFilePathURL) options:(ocidOption) |error|:(reference)
set ocidXMLDoc to (item 1 of listReadXML)

################################################
###### リンク取得
################################################
### root
set ocidRootElement to ocidXMLDoc's rootElement()
### channel
set ocidChannel to ocidRootElement's elementsForName:("channel")
set ocidChannelElement to ocidChannel's firstObject()
### ITEM
set ocidItemArray to (ocidChannelElement's elementsForName:("item"))
###リンク取得
set listURL to {} as list
repeat with itemElement in ocidItemArray
  set strItemTitle to (itemElement's elementsForName:("title"))'s stringValue as text
  ###
  if strItemTitle contains "mac.tar.xz" then
    set strItemLink to (itemElement's elementsForName:("link"))'s stringValue as text
    set end of listURL to strItemLink
  end if
end repeat

################################################
###### 念の為ソートする
################################################
set ocidURLArray to refMe's NSArray's arrayWithArray:(listURL)
set ocidURLArrayM to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
(ocidURLArrayM's addObjectsFromArray:(ocidURLArray))
###並び替え
set ocidDescriptor to (refMe's NSSortDescriptor's sortDescriptorWithKey:("self") ascending:(false) selector:"localizedStandardCompare:")
ocidURLArrayM's sortUsingDescriptors:{ocidDescriptor}
set strNewerFileURL to (ocidURLArrayM's firstObject()) as text
###取り出したダウンロードURL(最新)
set ocidURLString to refMe's NSString's stringWithString:(strNewerFileURL)
set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidURLString)
set ocidLastPathURL to ocidURL's URLByDeletingLastPathComponent()
###ファイル名
set strFileName to (ocidLastPathURL's lastPathComponent()) as text
###ダウンロードURL上書き
set strURL to ("https://www.7-zip.org/a/" & strFileName) as text
set ocidURLString to refMe's NSString's stringWithString:(strURL)
set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidURLString)

################################################
###### URLRequest部分
################################################
set ocidURLRequest to refMe's NSMutableURLRequest's alloc()'s init()
ocidURLRequest's setHTTPMethod:"GET"
ocidURLRequest's setURL:(ocidURL)
ocidURLRequest's addValue:"application/xml" forHTTPHeaderField:"Content-Type"
ocidURLRequest's setHTTPBody:(missing value)
################################################
###### データ取得
################################################
set ocidServerResponse to refMe's NSURLConnection's sendSynchronousRequest:(ocidURLRequest) returningResponse:(missing value) |error|:(reference)
###取得
set ocidXZData to (item 1 of ocidServerResponse)
################################################
###### 保存先
################################################
###保存先 ディレクトリ
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidTempDirURL to appFileManager's temporaryDirectory()
set ocidUUID to refMe's NSUUID's alloc()'s init()
set ocidUUIDString to ocidUUID's UUIDString
set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
###フォルダ作る
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
###保存パス
set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
set strSaveFilePathURL to (ocidSaveFilePathURL's |path|()) as text
####保存
set listDone to ocidXZData's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error|:(reference)
################################################
###### 展開
################################################
###展開先
set ocidHomeDirURL to appFileManager's homeDirectoryForCurrentUser()
set ocidSaveDirPathURL to ocidHomeDirURL's URLByAppendingPathComponent:("bin/7zip") isDirectory:true
set strSaveDirPathURL to (ocidSaveDirPathURL's |path|()) as text
###フォルダ作る
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
##展開
set strCommandText to ("/usr/bin/bsdtar -xvzf \"" & strSaveFilePathURL & "\" -C \"" & strSaveDirPathURL & "\"") as text
set strResponse to (do shell script strCommandText) as text


###################################
###保存先を開く
###################################
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set boolDone to appSharedWorkspace's openURL:(ocidSaveDirPathURL)
if boolDone is false then
  set aliasFilePathURL to (ocidSaveDirPathURL's absoluteURL()) as alias
  set boolResults to (appShardWorkspace's openURL:ocidCloudStorageDirURL)
  if boolResults is false then
    tell application "Finder"
make new Finder window to aliasFilePathURL
    end tell
  end if
end if




|

[bash]7zzインストール


#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
#ユーザード ~/binにインストールする

###ダウンロードURL
STR_URL="https://www.7-zip.org/a/7z2301-mac.tar.xz"

########################################
###管理者インストールしているか?チェック
USER_WHOAMI=$(/usr/bin/whoami)
/bin/echo "実行ユーザーは:$USER_WHOAMI"
###実行しているユーザー名
CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }')
/bin/echo "コンソールユーザー:$CONSOLE_USER"
###ログイン名ユーザー名※Visual Studio Codeの出力パネルではrootになる設定がある
LOGIN_NAME=$(/usr/bin/logname)
/bin/echo "ログイン名:$LOGIN_NAME"
###UID
USER_NAME=$(/usr/bin/id -un)
/bin/echo "ユーザー名:$USER_NAME"
###SUDOUSER
/bin/echo "SUDO_USER: $SUDO_USER"
########################################
###ダウンロード起動時に削除する項目
USER_TEMP_DIR=$(/usr/bin/mktemp -d)
/bin/echo "起動時に削除されるディレクトリ:" "$USER_TEMP_DIR"
############################################################
############################################################
###BIN
/bin/mkdir -p "/Users/$CONSOLE_USER/bin/"
for ((numTimes = 1; numTimes <= 3; numTimes++)); do
sleep 1
/bin/mkdir -p "/Users/$CONSOLE_USER/bin/7zip"
/usr/bin/touch "/Users/$CONSOLE_USER/bin/7zip"
/usr/sbin/chown "$CONSOLE_USER" "/Users/$CONSOLE_USER/bin/7zip"
/bin/chmod 700 "/Users/$CONSOLE_USER/bin"
done

###ファイル名を取得
DL_FILE_NAME=$(/usr/bin/curl -s -L -I -o /dev/null -w '%{url_effective}' "$STR_URL" | /usr/bin/rev | /usr/bin/cut -d'/' -f1 | /usr/bin/rev)
/bin/echo "DL_FILE_NAME:$DL_FILE_NAME"
###ダウンロード
if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/$DL_FILE_NAME" "$STR_URL" --connect-timeout 20; then
/bin/echo "ファイルのダウンロードに失敗しました HTTP1.1で再トライします"
  if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/$DL_FILE_NAME" "$STR_URL" --http1.1 --connect-timeout 20; then
/bin/echo "ファイルのダウンロードに失敗しました"
exit 1
  fi
fi
##全ユーザー実行可能にしておく
/bin/chmod 755 "$USER_TEMP_DIR/$DL_FILE_NAME"
/bin/echo "ダウンロードOK"
/bin/mkdir -p "$USER_TEMP_DIR/7zip/"
############################################################
######### インストール
/bin/echo "インストール開始:" "$CONSOLE_USER"
####解凍
## /usr/bin/bsdtar -xzf "$USER_TEMP_DIR/$DL_FILE_NAME" -C "$USER_TEMP_DIR/7zip" --strip-components=1
/usr/bin/bsdtar -xzf "$USER_TEMP_DIR/$DL_FILE_NAME" -C "$USER_TEMP_DIR/7zip"
sleep 2
###旧バージョンをゴミ箱に
USER_TRASH_DIR=$(/usr/bin/mktemp -d "$HOME/.Trash/7ZZ.XXXXXXXX")
/bin/mv "/Users/$CONSOLE_USER/bin/7zip/7zz" "$USER_TRASH_DIR"

####移動
/usr/bin/ditto "$USER_TEMP_DIR/7zip" "/Users/$CONSOLE_USER/bin/7zip"
####終了
/bin/echo "インストール終了:" "$CONSOLE_USER"
###保存先を開く
/usr/bin/open "/Users/$CONSOLE_USER/bin/7zip"
exit 0


|

Archive Utility 便利キット

ダウンロード - Archive Utility.zip

|

[7zz]パスワード付きで圧縮する

ダウンロード - e3838fe3829ae382b9e383afe383bce38388e38299e4bb98e3818de59ca7e7b8ae.dmg


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.6"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

on run
  log "ドロップレット限定用"
end run


on open listDropObject
  ###NSFileManager初期化
  set appFileManager to refMe's NSFileManager's defaultManager()
  ###Path to me
  tell application "Finder"
    set aliasPathToMe to (path to me) as alias
  end tell
  ###UNIXパス
  set strPathToMe to (POSIX path of aliasPathToMe) as text
  ##7zzバイナリーへのパス
  set strBinPath to (strPathToMe & "/Contents/bin/7zz") as text
  ###ドロップの数だけ繰返し
  repeat with itemDropObject in listDropObject
    #################################
    ###処理する判定
    set boolChkAliasPath to true as boolean
    try
tell application "Finder"
set strKind to (kind of itemDropObject) as text
end tell
    on error
log "シンボリックリンク等kindを取得できないファイルは処理しない"
set boolChkAliasPath to false as boolean
    end try
    if strKind is "アプリケーション" then
log "アプリケーションは処理しない"
set boolChkAliasPath to false as boolean
    else if strKind is "ボリューム" then
log "ボリュームは処理しない"
set boolChkAliasPath to false as boolean
    else if strKind is "エイリアス" then
log "エイリアスは処理しない"
set boolChkAliasPath to false as boolean
    end if
    #################################
    ###trueの場合のみ圧縮処理する
    if boolChkAliasPath is true then
########################################
#####パスワード生成 UUIDを利用
###生成したUUIDからハイフンを取り除く
set ocidUUIDString to (refMe's NSMutableString's alloc()'s initWithCapacity:0)
set ocidConcreteUUID to refMe's NSUUID's UUID()
(ocidUUIDString's setString:(ocidConcreteUUID's UUIDString()))
set ocidUUIDRange to (ocidUUIDString's rangeOfString:ocidUUIDString)
(ocidUUIDString's replaceOccurrencesOfString:("-") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidUUIDRange)
set strOwnerPassword to ocidUUIDString as text
########################################
#####パス
set strFilePath to (POSIX path of itemDropObject) as text
set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false)
set ocidDirName to ocidFilePathURL's lastPathComponent()
set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
set strDirName to ocidDirName as text
set strMakeDirName to (strDirName & "_圧縮済")
set ocidBaseFilePathURL to (ocidContainerDirPathURL's URLByAppendingPathComponent:strMakeDirName)
#####################
###フォルダを作る
set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions))
set listBoolMakeDir to (appFileManager's createDirectoryAtURL:(ocidBaseFilePathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference))
#####################
###zipPath
set ocidDirFilePathURL to (ocidBaseFilePathURL's URLByAppendingPathComponent:(ocidDirName))
set ocidZipFilePathURL to (ocidDirFilePathURL's URLByAppendingPathExtension:"zip")
set strZipFilePathURL to ocidZipFilePathURL's |path|() as text
########################################
#####パスワード生成 UUIDを利用
set strTextFileName to strDirName & ".pw.txt"
set ocidTextFilePathURL to (ocidBaseFilePathURL's URLByAppendingPathComponent:strTextFileName)
###テキスト
set strTextFile to "先にお送りしました圧縮ファイルの\n解凍パスワードをお知らせします\n\n" & strOwnerPassword & "\n\n解凍出来ない等ありましたらお知らせください。\n" as text
set ocidPWString to (refMe's NSString's stringWithString:strTextFile)
set ocidUUIDData to (ocidPWString's dataUsingEncoding:(refMe's NSUTF8StringEncoding))
#####パスワードを書いたテキストファイルを保存
set boolResults to (ocidUUIDData's writeToURL:ocidTextFilePathURL atomically:true)
########################################
#####コマンド実行
set strCommandText to ("\"" & strBinPath & "\" a \"" & strZipFilePathURL & "\" -p" & strOwnerPassword & " \"" & strFilePath & "\"")
do shell script strCommandText
    end if
  end repeat
return "処理終了"
end open


|

その他のカテゴリー

Acrobat Acrobat Annotation Acrobat Dialog Acrobat Form Acrobat JS Acrobat Open Acrobat Plugin Acrobat python Acrobat Reader Acrobat Sequ Acrobat Stamps Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin System Information Admin Tools Admin Users Admin Volumes Adobe Apple AppleScript AppleScript Guide AppleScript Accessibility AppleScript AppKit AppleScript Applications AppleScript AppStore AppleScript Archive AppleScript Attributes AppleScript Automator AppleScript AVAsset AppleScript AVconvert AppleScript AVFoundation AppleScript AVURLAsset AppleScript BackUp AppleScript Barcode AppleScript Bash AppleScript Basic AppleScript Basic Path AppleScript Bluetooth AppleScript BOX AppleScript Browser AppleScript Calendar AppleScript CD/DVD AppleScript Choose AppleScript Chrome AppleScript CIImage AppleScript CloudStorage AppleScript Color AppleScript com.apple.LaunchServices.OpenWith AppleScript Console AppleScript Contacts AppleScript CotEditor AppleScript CURL AppleScript current application AppleScript Date&Time AppleScript delimiters AppleScript Desktop AppleScript Device AppleScript Disk AppleScript do shell script AppleScript Dock AppleScript DropBox AppleScript eMail AppleScript Encode Decode AppleScript Error AppleScript EXIFData AppleScript ffmpeg AppleScript File AppleScript Finder AppleScript Firefox AppleScript Folder AppleScript Fonts AppleScript GIF AppleScript HTML AppleScript Icon AppleScript Illustrator AppleScript Image Events AppleScript Image2PDF AppleScript ImageOptim Applescript iWork AppleScript Javascript AppleScript Jedit AppleScript Json AppleScript Label AppleScript List AppleScript locationd AppleScript LRC AppleScript LSSharedFileList AppleScript m3u8 AppleScript MakePDF AppleScript Map AppleScript Math AppleScript Microsoft AppleScript Microsoft Edge AppleScript Microsoft Excel AppleScript Mobileconfig AppleScript Mouse AppleScript Movie AppleScript Music AppleScript NetWork AppleScript Notes AppleScript NSArray AppleScript NSBitmapImageRep AppleScript NSBundle AppleScript NSCFBoolean AppleScript NSCharacterSet AppleScript NSColor AppleScript NSColorList AppleScript NSData AppleScript NSDictionary AppleScript NSError AppleScript NSEvent AppleScript NSFileAttributes AppleScript NSFileManager AppleScript NSFont AppleScript NSFontManager AppleScript NSImage AppleScript NSIndex AppleScript NSKeyedArchiver AppleScript NSKeyedUnarchiver AppleScript NSLocale AppleScript NSMutableArray AppleScript NSMutableDictionary AppleScript NSMutableString AppleScript NSNotFound AppleScript NSNumber AppleScript NSOpenPanel AppleScript NSPasteboard AppleScript NSPDFImageRep AppleScript NSpoint AppleScript NSPredicate AppleScript NSRange AppleScript NSRegularExpression AppleScript NSRunningApplication AppleScript NSScreen AppleScript NSSize AppleScript NSString AppleScript NSStringCompareOptions AppleScript NSTask AppleScript NSTimeZone AppleScript NSURL AppleScript NSURL File AppleScript NSURLBookmark AppleScript NSURLComponents AppleScript NSURLResourceKey AppleScript NSUserDefaults AppleScript NSUUID AppleScript NSView AppleScript NSWorkspace AppleScript Numbers AppleScript OAuth AppleScript ObjC AppleScript OneDrive AppleScript Osax AppleScript PDF AppleScript PDFAnnotationWidget AppleScript PDFContext AppleScript PDFDisplayBox AppleScript PDFDocumentPermissions AppleScript PDFKit AppleScript PDFnUP AppleScript PDFOutline AppleScript Photos AppleScript Photoshop AppleScript Plist System Events AppleScript PostScript AppleScript prefPane AppleScript Preview AppleScript Python AppleScript QR AppleScript QR Decode AppleScript QuickLook AppleScript QuickTime AppleScript record AppleScript Regular Expression AppleScript Reminders AppleScript ReName AppleScript Repeat AppleScript RTF AppleScript Safari AppleScript SaveFile AppleScript ScreenCapture AppleScript ScreenSaver AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript Sort AppleScript Sound AppleScript Spotlight AppleScript SRT AppleScript StandardAdditions AppleScript stringByApplyingTransform AppleScript System Events AppleScript System Settings AppleScript TemporaryItems AppleScript Terminal AppleScript Text AppleScript Text CSV AppleScript Text TSV AppleScript TextEdit AppleScript Translate AppleScript Trash AppleScript Twitter AppleScript UI AppleScript Unit Conversion AppleScript UTType AppleScript valueForKeyPath AppleScript Video AppleScript VisionKit AppleScript Visual Studio Code AppleScript webarchive AppleScript webp AppleScript Wifi AppleScript XML AppleScript XML EPUB AppleScript XML OPML AppleScript XML Plist AppleScript XML RSS AppleScript XML SVG AppleScript XML TTML AppleScript XML webloc AppleScript YouTube AppleScript Zero Suppress Applications Barcode OnLine Tools CityCode Design iPhone List Logs lsappinfo Memo Music perl PlistBuddy pluginkit postalcode ReadMe SF Symbols character id SF Symbols Entity sips Skype Slack sqlite TCC Tools Typography Video Wacom zoom