applescript oneliner

tig*_*tig 0 applescript

是否可以将applescript线连接成一个(在红宝石中可以使用;)?

Phi*_*gan 5

并不是的.可以做的最多是采取一个简单的if-then声明,并使其成为一行......

if (variable) then 
    return true
end if
Run Code Online (Sandbox Code Playgroud)

... ...变

if (variable) then return true
Run Code Online (Sandbox Code Playgroud)

如果要osascript在shell脚本中包含该命令,则必须使用多个行脚本分隔-e...

osascript -e 'if (variable) then' -e 'return true' -e 'end if'
Run Code Online (Sandbox Code Playgroud)

但那是关于它的程度.AppleScript的文件不是简单的文本文件,像大多数其他编程语言(不幸),我们必须依靠其在线管理专业的编辑器.


smi*_*lov 5

这取决于你的代码。

当您使用 AppleScript 进行 GUI 脚本编写时,您通常可以将一堆嵌套的告诉块编写为一行。

例如这些嵌套的告诉块:

tell application "System Preferences"
    activate
end tell

tell application "System Events"
    tell application process "System Preferences"
        tell window "System Preferences"
            tell scroll area 1
                tell button "General"
                    click
                end tell
            end tell
        end tell
    end tell
end tell
Run Code Online (Sandbox Code Playgroud)

它们也可以写成:

tell application "System Preferences" to activate
tell application "System Events" to tell application process "System Preferences" to tell window "System Preferences" to tell scroll area 1 to tell button "General" to click
Run Code Online (Sandbox Code Playgroud)