在工作流中将项目从Automator传递到AppleScript

问题描述 投票:0回答:1

我有一个要求以下内容的Automator工作流程:

“询问取景器项目”“运行Apple脚本”

问题是我无法获得选择要在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
applescript automator
1个回答
0
投票

[添加Run AppleScript操作时,您会注意到是否附带一些以on run {input, parameters}开头的默认代码。 Input是包含上一个操作结果的变量:在这种情况下,Get Selected Finder Items返回别名列表,因此您可以像这样访问它们:

automator screenshot

轻松自在...

© www.soinside.com 2019 - 2024. All rights reserved.