首页 > 解决方案 > 如何从 Applescript 启动特定版本的 Illustrator?

问题描述

我安装了两个版本的 Illustrator,Adobe Illustrator 2020 和 Adob​​e Illustrator CC 2019。如何从 Applescript 确保选择了 Adob​​e Illustrator CC 2019?

为此,我进行了以下 applescript 编码,但 applescript 会自动更改应用程序名称。

set theResult to every paragraph of (do shell script "mdfind 'kMDItemContentTypeTree == \"com.apple.application\"c' | sort")
set systemApps to {}
set applicationsApps to {}
set Version2019 to "" as string
set Version2020 to "" as string
repeat with i from 1 to number of items in theResult
    set end of systemApps to item i of theResult
    
    if item i of theResult contains "Adobe Illustrator CC 2019" then
        set end of applicationsApps to item i of theResult
        set Version2019 to "true" as string
        exit repeat
    end if
    
end repeat
repeat with i from 1 to number of items in theResult
    set end of systemApps to item i of theResult
    
    if item i of theResult contains "Adobe Illustrator 2020" then
        set end of applicationsApps to item i of theResult
        set Version2020 to "true" as string
        exit repeat
    end if
    
end repeat
--display dialog (Version2019)
tell application "Finder"
    
    if (Version2019 contains "true" and Version2020 contains "true") then
        --display dialog "hey! " & theUser & return & return & "Adobe Illustrator 2019 and Adobe Illustrator 2020 available in this Mac" buttons {"Ok"}
        set questionStudio to display dialog "hey! " & return & return & "Adobe Illustrator 2019 and Adobe Illustrator 2020 available in this Mac." & return & return & "Please select Version:" buttons {"Adobe Illustrator CC 2019", "Adobe Illustrator 2020", "Cancel"}
        set answerStudio to button returned of questionStudio
        
        if answerStudio contains "Adobe Illustrator 2020" then
            tell application "/Applications/Adobe Illustrator 2020/Adobe Illustrator.app"
                if it is not running then launch
            end tell
            it is running
            return 0
            
        else if answerStudio contains "Adobe Illustrator 2019" then
            tell application "/Applications/Adobe Illustrator CC 2019/Adobe Illustrator.app"
                if it is not running then launch
            end tell
            it is running
            return 0
            
        else if answerStudio contains "Cancel" then
            tell me to quit
        end if
        
    else if (Version2019 contains "true") then
        --tell application "Finder"
        set appVersion to "Adobe Illustrator 2019"
        --end tell
    else if (Version2020 contains "true") then
        --tell application "Finder"
        set appVersion to "Adobe Illustrator 2020"
        --end tell
    end if
end tell

标签: applescript

解决方案


使用应用程序的完整路径,而不仅仅是其名称。

另请注意,Finder 中显示的应用程序名称可能不是其真实文件名。

获取应用程序完整路径的最简单方法是将其图标拖放到脚本编辑器窗口中。

例子:

tell application "/Applications/Adobe Illustrator 2020/Adobe Illustrator.app"
    …
end tell

推荐阅读