【问题标题】:How to include Automator variables in AppleScript?如何在 AppleScript 中包含 Automator 变量?
【发布时间】:2016-04-06 20:44:28
【问题描述】:

我正在制作一个自动化服务来选择一个文件,然后使用 shell 脚本上传选定的文件。我似乎无法让我的变量发挥作用。我对 Automator 和 AppleScript 非常陌生,对它们了解不多,所以它们可能只是新手的错误。

如果有更好的方法,请告诉我!

这是我的 AppleScript 代码:

on run {input01, input02, path}
    set input01 to "scp -i /Users/jeffArries/Desktop/jeffarries.pem -rp /Users/jeffArries/Desktop/Website_Testing_Folder/"
    set input02 to "ec2-user@ec2-54-213-219-247.us-west-2.compute.amazonaws.com:/var/www/html"
    do shell script "{input01} & {Path} & {input02}"
end run

还有automator截图:

【问题讨论】:

    标签: shell ssh applescript automator


    【解决方案1】:

    您无需按照自己的方式进行操作。创建 Automator 服务时,所选项目的路径会自动提供给该服务。 您需要做的就是在顶部的菜单中选择“文件和文件夹”(在您的屏幕截图中,您选择了“no input”)。

    之后您不需要使用 Automator 变量,所有路径都可以在input 参数中作为列表找到。

    之后你应该像普通字符串一样构建你的shell命令并通过do shell script执行它。

    试试这个开始,我为你填满了有用的 cmets:

    on run {input, parameters}
    
        -- setting your AppleScript variables
        set input01 to "scp -i /Users/jeffArries/Desktop/jeffarries.pem -rp /Users/jeffArries/Desktop/Website_Testing_Folder/"
        set input02 to "ec2-user@ec2-54-213-219-247.us-west-2.compute.amazonaws.com:/var/www/html"
    
        -- loop through selected finder items
        repeat with aFinderItem in input
            -- check if the aFinderItem is a file and not anything else
            tell application "System Events" to set theItemIsAFile to ((get class of item (aFinderItem as text)) = file)
            if theItemIsAFile then
                -- store the POSIX path of the file
                set theItemsPosixPath to POSIX path of aFinderItem
                -- build the shell scp command
                set myShellCommand to input01 & " " & quoted form of theItemsPosixPath & " " & input02
                -- exceute the command
                do shell script myShellCommand
            end if
        end repeat
        return input
    end run
    

    享受吧,迈克尔/汉堡

    【讨论】:

      猜你喜欢
      • 2014-02-18
      • 2023-03-18
      • 2013-04-13
      • 2020-12-23
      • 2013-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-09
      相关资源
      最近更新 更多