Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
applescript oneliner_Applescript - Fatal编程技术网

applescript oneliner

applescript oneliner,applescript,Applescript,是否可以将applescript行合并为一行(在ruby中可以使用;)?不太可能。我们能做的最多的就是用一个简单的if-then语句将它写成一行 if (variable) then return true end if …变成 if (variable) then return true 如果要在shell脚本中包含osascript命令,则多行脚本必须用-e分隔 osascript -e 'if (variable) then' -e 'return true' -e 'end

是否可以将applescript行合并为一行(在ruby中可以使用
)?

不太可能。我们能做的最多的就是用一个简单的
if-then
语句将它写成一行

if (variable) then 
    return true
end if
…变成

if (variable) then return true
如果要在shell脚本中包含
osascript
命令,则多行脚本必须用
-e
分隔

osascript -e 'if (variable) then' -e 'return true' -e 'end if'

但这就是它的范围。Applescript文件不像大多数其他编程语言那样是简单的文本文件(不幸的是),我们必须依靠其专门的编辑器进行行管理。

不太可能。我们能做的最多的就是用一个简单的
if-then
语句将它写成一行

if (variable) then 
    return true
end if
…变成

if (variable) then return true
如果要在shell脚本中包含
osascript
命令,则多行脚本必须用
-e
分隔

osascript -e 'if (variable) then' -e 'return true' -e 'end if'

但这就是它的范围。Applescript文件不像大多数其他编程语言那样是简单的文本文件(不幸的是),我们必须依靠其专门的编辑器进行行管理。

如果您真的想避免
-e
并将所有内容强制放在一行,您可以通过
echo

osascript -e "`echo -e \"tell application \\"MyApp\\"\nactivate\nend tell\"`"

其中
变为
\\”
而换行符变为
\n

如果您真的想避免
-e
并将所有内容强制放在一行上,您可以将所有内容推送到
echo

osascript -e "`echo -e \"tell application \\"MyApp\\"\nactivate\nend tell\"`"

如果
变为
\\”
并且换行符变为
\n

,这取决于您的代码

使用AppleScript编写GUI脚本时,通常可以将一组嵌套的tell块作为一行编写

例如,这些嵌套的tell块:

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
它们也可以写成:

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

这取决于你的代码

使用AppleScript编写GUI脚本时,通常可以将一组嵌套的tell块作为一行编写

例如,这些嵌套的tell块:

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
它们也可以写成:

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

我已将AppleScript从块格式重新排列为单行格式,如下所示:

块格式

tell application <application>
  activate
  open location <url>
end tell
告诉应用程序
激活
开放位置
结束语
单行格式


osascript-e“告诉应用程序”激活并打开位置\”

我已将AppleScript从块格式重新排列为单行格式,如下所示:

块格式

tell application <application>
  activate
  open location <url>
end tell
告诉应用程序
激活
开放位置
结束语
单行格式


osascript-e“告诉应用程序”激活并打开位置\”

您想做什么?你想拥有一大堆可以按需执行的命令吗?我一年前问过这个问题,很难准确地记住:)我认为这是关于使用
osascript-e…
你想做什么?你想拥有一大堆可以按需执行的命令吗?我一年前问过这个问题,很难准确记住:)我认为这是关于使用
osascript-e…
这可能对通过搜索来到这里的人有所帮助,但这仍然不允许将这两个tell呼叫连接到一条线路这可能对通过搜索到达这里的人有所帮助,但这仍然不允许将这两个tell呼叫连接到一条线路这是不必要的。只要
osascript-e$'tell应用程序“MyApp”\n激活\n并告诉“
就足够了。这是不必要的。只要
osascript-e$'tell application“MyApp”\n激活\n并告诉“
就足够了。+1对于多个
-e
语句,从来没有想过这样做。谢谢(在我的例子中,我想在Makefile配方中嵌入一块AppleScript,它不能很好地处理换行符…)+1表示多个
-e
语句,从未想过这样做。谢谢(在我的例子中,我想在一个Makefile配方中嵌入一大块AppleScript,它不能很好地处理换行符…)