在工作流程中将项目从 Automator 传递到 AppleScript
Passing item from Automator to AppleScript in a workflow
我有一个 Automator 工作流程要求:
"Ask for finder items"
"Run Apple Script"
问题是我无法获取选择用于我的 Apple 脚本的项目。
set display_text to "Please enter your password:"
repeat
considering case
set init_pass to text returned of (display dialog display_text default answer "" with hidden answer)
set final_pass to text returned of (display dialog "Please verify your password below." buttons {"OK"} default button 1 default answer "" with hidden answer)
if (final_pass = init_pass) then
exit repeat
else
set display_text to "Mismatching passwords, please try again"
end if
end considering
end repeat
tell application "Finder"
#set theItems to choose folder with prompt "Please select a document to process:"
#set theItems to selected
set theItem to selection # This is where the problem is.
set theItem to (item 1 of theItems) as alias
set itemPath to quoted form of POSIX path of theItem
set fileName to name of theItem
set theFolder to POSIX path of (container of theItem as alias)
set zipFile to quoted form of (fileName & ".zip")
do shell script "cd '" & theFolder & "'; zip -x .DS_Store -r0 -P '" & final_pass & "' " & zipFile & " ./'" & fileName & "'"
end tell
当您添加 Run AppleScript
操作时,您会注意到是否带有一些默认代码,从 on run {input, parameters}
开始。 Input
是一个包含上次操作结果的变量:在本例中,Get Selected Finder Items
returns 是一个别名列表,因此您可以像这样访问它们:
轻松简单...
我有一个 Automator 工作流程要求:
"Ask for finder items" "Run Apple Script"
问题是我无法获取选择用于我的 Apple 脚本的项目。
set display_text to "Please enter your password:"
repeat
considering case
set init_pass to text returned of (display dialog display_text default answer "" with hidden answer)
set final_pass to text returned of (display dialog "Please verify your password below." buttons {"OK"} default button 1 default answer "" with hidden answer)
if (final_pass = init_pass) then
exit repeat
else
set display_text to "Mismatching passwords, please try again"
end if
end considering
end repeat
tell application "Finder"
#set theItems to choose folder with prompt "Please select a document to process:"
#set theItems to selected
set theItem to selection # This is where the problem is.
set theItem to (item 1 of theItems) as alias
set itemPath to quoted form of POSIX path of theItem
set fileName to name of theItem
set theFolder to POSIX path of (container of theItem as alias)
set zipFile to quoted form of (fileName & ".zip")
do shell script "cd '" & theFolder & "'; zip -x .DS_Store -r0 -P '" & final_pass & "' " & zipFile & " ./'" & fileName & "'"
end tell
当您添加 Run AppleScript
操作时,您会注意到是否带有一些默认代码,从 on run {input, parameters}
开始。 Input
是一个包含上次操作结果的变量:在本例中,Get Selected Finder Items
returns 是一个别名列表,因此您可以像这样访问它们:
轻松简单...