[pluginkit]Finder機能拡張 バージョン入りのIDの取得
ソース | |
---|---|
001 | #!/usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | (* |
004 | プラグインキットのバンドルIDから |
005 | バージョン入りのIDを取得します |
006 | |
007 | v1初回作成 |
008 | v1.1 +の処理を追加 |
009 | com.cocolog-nifty.quicktimer.icefloe *) |
010 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
011 | use AppleScript version "2.8" |
012 | use framework "Foundation" |
013 | use framework "UniformTypeIdentifiers" |
014 | use framework "AppKit" |
015 | use scripting additions |
016 | |
017 | property refMe : a reference to current application |
018 | |
019 | #取得したいID |
020 | set strBundleID to ("com.microsoft.OneDrive.FileProvider") as text |
021 | |
022 | set refResponse to doZshTaskStdOUT("/usr/bin/pluginkit -m | grep \"" & strBundleID & "\"") |
023 | if refResponse is false then |
024 | return "コマンド失敗" |
025 | else |
026 | set ocidPathToMeStr to refMe's NSString's stringWithString:(refResponse) |
027 | set ocidPathToMeStr to (ocidPathToMeStr's stringByReplacingOccurrencesOfString:("\r") withString:("")) |
028 | set ocidPathToMeStr to (ocidPathToMeStr's stringByReplacingOccurrencesOfString:("\n") withString:("")) |
029 | set ocidPathToMeStr to (ocidPathToMeStr's stringByReplacingOccurrencesOfString:("\t") withString:("")) |
030 | set ocidPathToMeStr to (ocidPathToMeStr's stringByReplacingOccurrencesOfString:(" ") withString:("")) |
031 | #追加 |
032 | set ocidPathToMeStr to (ocidPathToMeStr's stringByReplacingOccurrencesOfString:("+") withString:("")) |
033 | log ocidPathToMeStr as text |
034 | end if |
035 | |
036 | ################################### |
037 | # ZSH 実行 |
038 | ################################### |
039 | to doZshTaskStdOUT(argCommandText) |
040 | set strCommandText to argCommandText as text |
041 | set ocidCommandText to refMe's NSString's stringWithString:(strCommandText) |
042 | set ocidTermTask to refMe's NSTask's alloc()'s init() |
043 | ocidTermTask's setLaunchPath:"/bin/zsh" |
044 | ocidTermTask's setArguments:({"-c", ocidCommandText}) |
045 | #標準出力 |
046 | set ocidOutPut to refMe's NSPipe's pipe() |
047 | ocidTermTask's setStandardOutput:(ocidOutPut) |
048 | #エラー出力 |
049 | set ocidError to refMe's NSPipe's pipe() |
050 | ocidTermTask's setStandardError:(ocidError) |
051 | set listResults to ocidTermTask's launchAndReturnError:(reference) |
052 | if (item 1 of listResults) is true then |
053 | log "正常終了" |
054 | set ocidOutPutData to ocidOutPut's fileHandleForReading() |
055 | set listResponse to ocidOutPutData's readDataToEndOfFileAndReturnError:(reference) |
056 | set ocidStdOut to (item 1 of listResponse) |
057 | set ocidStdOut to refMe's NSString's alloc()'s initWithData:(ocidStdOut) encoding:(refMe's NSUTF8StringEncoding) |
058 | return (ocidStdOut as text) |
059 | else |
060 | try |
061 | set strResponse to (do shell script strCommandText) as text |
062 | on error |
063 | log " Zshでエラー" |
064 | return false |
065 | end try |
066 | end if |
067 | return true |
068 | end doZshTaskStdOUT |
AppleScriptで生成しました |
ソース | |
---|---|
001 | #!/usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | (* |
004 | プラグインキットのバンドルIDから |
005 | バージョン入りのIDを取得します |
006 | |
007 | com.cocolog-nifty.quicktimer.icefloe *) |
008 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
009 | use AppleScript version "2.8" |
010 | use framework "Foundation" |
011 | use framework "UniformTypeIdentifiers" |
012 | use framework "AppKit" |
013 | use scripting additions |
014 | |
015 | property refMe : a reference to current application |
016 | |
017 | #取得したいID |
018 | set strBundleID to ("com.microsoft.OneDrive.FileProvider") as text |
019 | |
020 | set refResponse to doZshTask("/usr/bin/pluginkit -m | grep \"" & strBundleID & "\"") |
021 | if refResponse is false then |
022 | return "コマンド失敗" |
023 | else |
024 | set ocidPathToMeStr to refMe's NSString's stringWithString:(refResponse) |
025 | set ocidPathToMeStr to (ocidPathToMeStr's stringByReplacingOccurrencesOfString:("\r") withString:("")) |
026 | set ocidPathToMeStr to (ocidPathToMeStr's stringByReplacingOccurrencesOfString:("\n") withString:("")) |
027 | set ocidPathToMeStr to (ocidPathToMeStr's stringByReplacingOccurrencesOfString:("\t") withString:("")) |
028 | set ocidPathToMeStr to (ocidPathToMeStr's stringByReplacingOccurrencesOfString:(" ") withString:("")) |
029 | log ocidPathToMeStr as text |
030 | end if |
031 | |
032 | ################################### |
033 | # ZSH 実行 |
034 | ################################### |
035 | to doZshTask(argCommandText) |
036 | set strCommandText to argCommandText as text |
037 | set ocidCommandText to refMe's NSString's stringWithString:(strCommandText) |
038 | set ocidTermTask to refMe's NSTask's alloc()'s init() |
039 | ocidTermTask's setLaunchPath:"/bin/zsh" |
040 | ocidTermTask's setArguments:({"-c", ocidCommandText}) |
041 | #標準出力 |
042 | set ocidOutPut to refMe's NSPipe's pipe() |
043 | ocidTermTask's setStandardOutput:(ocidOutPut) |
044 | #エラー出力 |
045 | set ocidError to refMe's NSPipe's pipe() |
046 | ocidTermTask's setStandardError:(ocidError) |
047 | set listResults to ocidTermTask's launchAndReturnError:(reference) |
048 | if (item 1 of listResults) is true then |
049 | log "正常終了" |
050 | set ocidOutPutData to ocidOutPut's fileHandleForReading() |
051 | set listResponse to ocidOutPutData's readDataToEndOfFileAndReturnError:(reference) |
052 | set ocidStdOut to (item 1 of listResponse) |
053 | set ocidStdOut to refMe's NSString's alloc()'s initWithData:(ocidStdOut) encoding:(refMe's NSUTF8StringEncoding) |
054 | return (ocidStdOut as text) |
055 | else |
056 | try |
057 | set strResponse to (do shell script strCommandText) as text |
058 | on error |
059 | log " Zshでエラー" |
060 | return false |
061 | end try |
062 | end if |
063 | return true |
064 | end doZshTask |
AppleScriptで生成しました |