Shell 如何在AppleScript中包含自动机变量?

Shell 如何在AppleScript中包含自动机变量?,shell,ssh,applescript,automator,Shell,Ssh,Applescript,Automator,我正在制作一个自动机服务来选择一个文件,然后使用shell脚本上传所选的文件。我似乎无法让我的变量工作。我对Automator和AppleScript非常陌生,对它们不太了解,所以它们可能只是新手犯的错误 如果有更好的方法,请告诉我 以下是我的AppleScript代码: 运行{input01,input02,path} 将input01设置为“scp-i/Users/jeffArries/Desktop/jeffArries.pem-rp/Users/jeffArries/Desktop/We

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

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

以下是我的AppleScript代码:

运行{input01,input02,path} 将input01设置为“scp-i/Users/jeffArries/Desktop/jeffArries.pem-rp/Users/jeffArries/Desktop/Website\u Testing\u Folder/” 将input02设置为“ec2”-user@ec2-54-213-219-247.us-west-2.compute.amazonaws.com:/var/www/html“ 执行shell脚本“{input01}&{Path}&{input02}” 终点
以及automator的屏幕截图:

您不需要按自己的方式操作。创建自动机服务时,所选项目的路径将自动提供给该服务。 您只需在顶部菜单中选择“文件和文件夹”(在屏幕截图中选择“无输入””)

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

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

尝试以下内容开始,我为您提供了一些有用的评论:

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

享受吧,迈克尔/汉堡

你不需要按自己的方式去做。创建自动机服务时,所选项目的路径将自动提供给该服务。 您只需在顶部菜单中选择“文件和文件夹”(在屏幕截图中选择“无输入””)

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

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

尝试以下内容开始,我为您提供了一些有用的评论:

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
享受吧,迈克尔/汉堡