« [CotEditor]前面書類がHTMLならSafariで開く | トップページ | [CURL]CURLヘッダー付きダウンローダー »

[Finder]UTIからアプリケーションを起動させる

#!/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.4"

use framework "Foundation"

use scripting additions


property refMe : a reference to current application



set strUTI to "com.google.Chrome" as text




########処理分岐(スクリプトメニュー対策)

tell current application

    set strName to name as text

end tell

if strName is "osascript" then

    tell application "Finder"

        ###UTIからアプリケーションのパスを取得

        set fileAppPath to application file id strUTI

        ###エリアス

        set aliasAppPath to fileAppPath as alias

        ###UNIXパス

        set strAppPath to POSIX path of aliasAppPath as text

        ###開く

        open aliasAppPath

    end tell

    set ocidAppBundle to refMe's NSBundle's bundleWithPath:strAppPath

    set ocidAppName to ocidAppBundle's objectForInfoDictionaryKey:"CFBundleDisplayName"

    set strAppName to ocidAppName as text

    tell application strAppName

        launch

        activate

    end tell

    return "Finderで起動しました"

else

    set ocidFalse to (refMe's NSNumber's numberWithBool:false)'s boolValue

    set ocidTrue to (refMe's NSNumber's numberWithBool:true)'s boolValue

    set ocidWorkspace to refMe's NSWorkspace's sharedWorkspace()

    set ocidAppBundlePathURL to ocidWorkspace's URLForApplicationWithBundleIdentifier:strUTI

    set ocidAppBundle to refMe's NSBundle's bundleWithURL:ocidAppBundlePathURL

    set strAppName to (ocidAppBundle's objectForInfoDictionaryKey:"CFBundleDisplayName") as text

    

    #####アプリケーションを起動する    

    set ocidOpenConfiguration to refMe's NSWorkspaceOpenConfiguration's configuration()

    ocidOpenConfiguration's setHides:ocidFalse

    ocidOpenConfiguration's setRequiresUniversalLinks:ocidFalse

    ocidOpenConfiguration's setActivates:ocidTrue

    ocidWorkspace's openApplicationAtURL:ocidAppBundlePathURL configuration:(ocidOpenConfiguration) completionHandler:(missing value)

    return "NSWorkspaceで起動しました"

    

end if










|

« [CotEditor]前面書類がHTMLならSafariで開く | トップページ | [CURL]CURLヘッダー付きダウンローダー »

Finder」カテゴリの記事

UTType」カテゴリの記事