001 | #!/usr/bin/env osascript |
---|
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
---|
003 | # |
---|
004 | # |
---|
005 | # com.cocolog-nifty.quicktimer.icefloe |
---|
006 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
---|
007 | ##自分環境がos12なので2.8にしているだけです |
---|
008 | use AppleScript version "2.8" |
---|
009 | use framework "Foundation" |
---|
010 | use framework "UniformTypeIdentifiers" |
---|
011 | use framework "AppKit" |
---|
012 | use scripting additions |
---|
013 | |
---|
014 | property refMe : a reference to current application |
---|
015 | set appFileManager to refMe's NSFileManager's defaultManager() |
---|
016 | |
---|
017 | ############################## |
---|
018 | #キーワード |
---|
019 | set strFileName to (".DS_Store") as text |
---|
020 | |
---|
021 | ############################## |
---|
022 | #ダイアログ |
---|
023 | set strName to (name of current application) as text |
---|
024 | if strName is "osascript" then |
---|
025 | tell application "Finder" to activate |
---|
026 | else |
---|
027 | tell current application to activate |
---|
028 | end if |
---|
029 | # |
---|
030 | set appFileManager to refMe's NSFileManager's defaultManager() |
---|
031 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask)) |
---|
032 | set ocidDesktopDirPathURL to ocidURLsArray's firstObject() |
---|
033 | set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias |
---|
034 | |
---|
035 | set strMes to "フォルダを選んでください" as text |
---|
036 | set strPrompt to "フォルダを選択してください" as text |
---|
037 | try |
---|
038 | set aliasDirPath to (choose folder strMes with prompt strPrompt default location aliasDefaultLocation with invisibles and showing package contents without multiple selections allowed) as alias |
---|
039 | on error |
---|
040 | log "エラーしました" |
---|
041 | return "エラーしました" |
---|
042 | end try |
---|
043 | ############################## |
---|
044 | #クローズパスをオープンディレクトリパスに |
---|
045 | set strDirPath to (POSIX path of aliasDirPath) as text |
---|
046 | set ocidDirPathStr to refMe's NSString's stringWithString:(strDirPath) |
---|
047 | set ocidDirPath to ocidDirPathStr's stringByStandardizingPath() |
---|
048 | set strDirPath to ocidDirPath as text |
---|
049 | |
---|
050 | ############################## |
---|
051 | #コマンド整形 |
---|
052 | set strCommandText to ("\"/usr/bin/find\" \"" & strDirPath & "\" -type f -name \"" & strFileName & "\"") as text |
---|
053 | log "\n" & strCommandText & "\n" |
---|
054 | #コマンド実行 |
---|
055 | set strExecCommand to ("/bin/zsh -c '" & strCommandText & "'") as text |
---|
056 | try |
---|
057 | set strResponse to (do shell script strExecCommand) as text |
---|
058 | |
---|
059 | on error |
---|
060 | log "osascript でエラーしました" |
---|
061 | return false |
---|
062 | end try |
---|
063 | |
---|
064 | ############################## |
---|
065 | # |
---|
066 | set ocidResponseString to refMe's NSMutableString's stringWithString:(strResponse) |
---|
067 | set ocidPathArray to ocidResponseString's componentsSeparatedByString:("\r") |
---|
068 | # |
---|
069 | set numCntArray to ocidPathArray's |count|() |
---|
070 | if numCntArray = 1 then |
---|
071 | set strChkResponse to ocidPathArray's firstObject() as text |
---|
072 | if strChkResponse is "" then |
---|
073 | display alert "対象ファイルはありませんでした" giving up after 2 |
---|
074 | return |
---|
075 | end if |
---|
076 | end if |
---|
077 | |
---|
078 | |
---|
079 | ############################## |
---|
080 | # |
---|
081 | repeat with itemPath in ocidPathArray |
---|
082 | set strFilePath to itemPath as text |
---|
083 | set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath)) |
---|
084 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
---|
085 | set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false) |
---|
086 | set ocidFileName to ocidFilePathURL's lastPathComponent() |
---|
087 | #ゴミ箱 |
---|
088 | set appFileManager to refMe's NSFileManager's defaultManager() |
---|
089 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSTrashDirectory) inDomains:(refMe's NSUserDomainMask)) |
---|
090 | set ocidTrashDirPathURL to ocidURLsArray's firstObject() |
---|
091 | set ocidDistResultURL to (ocidTrashDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:(true)) |
---|
092 | # |
---|
093 | set boolDirExists to (appFileManager's fileExistsAtPath:(ocidFilePath) isDirectory:(false)) |
---|
094 | if boolDirExists = true then |
---|
095 | set appFileManager to refMe's NSFileManager's defaultManager() |
---|
096 | set somesome to "" |
---|
097 | set listDone to (appFileManager's trashItemAtURL:(ocidFilePathURL) resultingItemURL:(ocidDistResultURL) |error| :(reference)) |
---|
098 | if (item 2 of listDone) ≠ (missing value) then |
---|
099 | set strErrorNO to (item 2 of listDone)'s code() as text |
---|
100 | set strErrorMes to (item 2 of listDone)'s localizedDescription() as text |
---|
101 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
---|
102 | return "エラーしました" & strErrorNO & strErrorMes |
---|
103 | end if |
---|
104 | else if boolDirExists = false then |
---|
105 | log "何らかの理由でファイルを見つけられませんでした" |
---|
106 | log strFilePath |
---|
107 | end if |
---|
108 | |
---|
109 | end repeat |
---|