将两个项目设置为输入到 automator 中的 shell 脚本
Set two items as input to a shell script inside automator
我有这个 Automator,它是作为图像查找器服务添加的。
这一切都是从用户选择一堆图像并在服务菜单上选择脚本开始的。
然后脚本首先询问用户两个问题:
on run {input, parameters}
choose from list {"iPhone", "iPad", "Mac"} with prompt "Choose Platform"
set platform to the result as string
display dialog "Choose File Name" default answer ""
set fileName to the result as string
// here it goes the magic line
return input
end run
当场 "here it goes the magic line" 我想添加一行,将 platform
和 fileName
作为两个条目添加到将传递的参数(输入?)的数组(?)中shell 脚本将跟随此 AppleScript
.
shell 脚本将包含这些行:
platform=
shift
fileName=
shift
for f in "$@"; do
// files will be processed here
我不确定 shell 脚本将如何接收,但据我所知,它应该接收类似数组的内容,由 3 项组成:平台、文件名和所选文件的列表。我知道 shift 会删除输入开头的项目。
出于这个原因,我尝试了这些行:
set beginning of input to platform as string and fileName as string
还有
set beginning of input to platform
set beginning of input to fileName
//hoping it will push platform to the second position
但 none 有效。
任何想法
这应该会为您解决这个问题:
on run {input, parameters}
set platform to (choose from list {"iPhone", "iPad", "Mac"} with prompt "Choose Platform") as string
set fileName to text returned of (display dialog "Choose File Name" default answer "") as string
set tempList to {}
set end of tempList to platform
set end of tempList to fileName
repeat with i from 1 to count of input
set end of tempList to item i of input
end repeat
copy tempList to input
return input
end run
这也行,我刚测试过:
on run {input, parameters}
set platform to (choose from list {"iPhone", "iPad", "Mac"} with prompt "Choose Platform") as string
set fileName to text returned of (display dialog "Choose File Name" default answer "") as string
set beginning of input to fileName
set beginning of input to platform
return input
end run
请注意,这只是 示例代码,并未采用任何错误处理。
我相信在这个用例中,您需要一次将一个项目添加到列表中。
我有这个 Automator,它是作为图像查找器服务添加的。
这一切都是从用户选择一堆图像并在服务菜单上选择脚本开始的。
然后脚本首先询问用户两个问题:
on run {input, parameters}
choose from list {"iPhone", "iPad", "Mac"} with prompt "Choose Platform"
set platform to the result as string
display dialog "Choose File Name" default answer ""
set fileName to the result as string
// here it goes the magic line
return input
end run
当场 "here it goes the magic line" 我想添加一行,将 platform
和 fileName
作为两个条目添加到将传递的参数(输入?)的数组(?)中shell 脚本将跟随此 AppleScript
.
shell 脚本将包含这些行:
platform=
shift
fileName=
shift
for f in "$@"; do
// files will be processed here
我不确定 shell 脚本将如何接收,但据我所知,它应该接收类似数组的内容,由 3 项组成:平台、文件名和所选文件的列表。我知道 shift 会删除输入开头的项目。
出于这个原因,我尝试了这些行:
set beginning of input to platform as string and fileName as string
还有
set beginning of input to platform
set beginning of input to fileName
//hoping it will push platform to the second position
但 none 有效。
任何想法
这应该会为您解决这个问题:
on run {input, parameters}
set platform to (choose from list {"iPhone", "iPad", "Mac"} with prompt "Choose Platform") as string
set fileName to text returned of (display dialog "Choose File Name" default answer "") as string
set tempList to {}
set end of tempList to platform
set end of tempList to fileName
repeat with i from 1 to count of input
set end of tempList to item i of input
end repeat
copy tempList to input
return input
end run
这也行,我刚测试过:
on run {input, parameters}
set platform to (choose from list {"iPhone", "iPad", "Mac"} with prompt "Choose Platform") as string
set fileName to text returned of (display dialog "Choose File Name" default answer "") as string
set beginning of input to fileName
set beginning of input to platform
return input
end run
请注意,这只是 示例代码,并未采用任何错误处理。
我相信在这个用例中,您需要一次将一个项目添加到列表中。