« [ショートカット]QRコードの『ファイル』をデコードする | トップページ | [NSimages]画像の解像度ppiを求める »

[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
###NSURLArrayに追加
(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
#########################

|

« [ショートカット]QRコードの『ファイル』をデコードする | トップページ | [NSimages]画像の解像度ppiを求める »

Finder」カテゴリの記事

NSWorkspace」カテゴリの記事

Trash」カテゴリの記事