[Finder]フォルダの中身をゴミ箱に入れる
#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
property refMe : a reference to current application
property refNSString : a reference to refMe's NSString
property refNSURL : a reference to refMe's NSURL
property refNSMutableArray : a reference to refMe's NSMutableArray
property refNSDirectoryEnumerationSkipsHiddenFiles : a reference to refMe's NSDirectoryEnumerationSkipsHiddenFiles
property refNSURLNameKey : a reference to refMe's NSURLNameKey
property refNSWorkspace : a reference to refMe's NSWorkspace
property objNSNotFound : a reference to 9.22337203685477E+18 + 5807
set objFileManager to refMe's NSFileManager's defaultManager()
######ログ表示
doLogView()
set strDirPath to do shell script "/bin/echo $HOME/Library/Logs/DiagnosticReports"
##Make NSString
set ocidNSString to refNSString's stringWithString:strDirPath
log ocidNSString as text
log ocidNSString's className() as text
###NSURL
set ocidURLPath to refNSURL's fileURLWithPath:ocidNSString
log ocidURLPath as text
log ocidURLPath's className() as text
###NSURLのディレクトリの中身
set ocidFileAliasArray to objFileManager's contentsOfDirectoryAtURL:ocidURLPath includingPropertiesForKeys:{refNSURLNameKey} options:refNSDirectoryEnumerationSkipsHiddenFiles |error|:(missing value)
log ocidFileAliasArray as list
log className() of ocidFileAliasArray as text
####フォルダ中身の分だけ繰り返し
repeat with objFileAlias in ocidFileAliasArray
###ゴミ箱へ入れる
set boolGoToTrash to (objFileManager's trashItemAtURL:objFileAlias resultingItemURL:(missing value) |error|:(""))
####戻値がfalse=失敗なら
if boolGoToTrash is false then
###問題のファイルを
set ocidOpenFinderURLsArray to (refNSMutableArray's alloc()'s initWithCapacity:0)
log ocidOpenFinderURLsArray as list
###NSURLをArrayに追加
(ocidOpenFinderURLsArray's addObject:objFileAlias)
###Finderに表示
(refNSWorkspace's sharedWorkspace()'s activateFileViewerSelectingURLs:ocidOpenFinderURLsArray)
log "移動に失敗しました"
exit repeat
end if
end repeat
#########################ログ表示
to doLogView()
tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
tell application "Script Editor"
tell application "System Events"
tell process "Script Editor"
tell window 1
tell splitter group 1
tell splitter group 1
tell group 1
tell checkbox "返された値"
set boolValue to value as boolean
end tell
if boolValue is false then
click checkbox "返された値"
end if
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end if
end repeat
end doLogView
#########################
| 固定リンク
「Finder」カテゴリの記事
- [Finder] AppleScript で Finder 項目を選択する(新規FInder Windowを作って指定ファイルを選択)(2025.01.09)
- Dock再起動(2024.12.14)
- SystemUIServer再起動(Menu barほか)(2024.12.14)
- Finder再起動(2024.12.14)
- [Finder]エイリアスの参照元の取得(2024.12.02)
「NSWorkspace」カテゴリの記事
- [Open]iBookの保存先を開く(2025.01.08)
- Macでファイルを開くアプリを選択する(ファイルをデフォルトで開くアプリを設定・変更する)(2024.11.03)
- バンドルIDからアプリケーションのインストールURLを取得(2024.10.11)
- iCloud Driveを開く(2023.11.06)
- 新規インスタンスで起動させる(2023.10.05)
「Trash」カテゴリの記事
- [AppleScript 基本]ゴミ箱に入れる(2025.01.16)
- [考察]$HOME/Library/Containers/以下のファイル操作(削除)(2024.05.05)
- [メンテナンス] Containers 配下の全てのCachesをゴミ箱に入れる(2023.09.17)
- [Finder 設定]ゴミ箱を空にする時の警告の有無(2023.08.14)
- [bash]全てのローカルアカウントのゴミ箱を空にする 少し修正(警告出ないようにした)(2023.08.14)