Scripting AppleScript:从随机文件夹读取主脚本

Scripting AppleScript:从随机文件夹读取主脚本,scripting,applescript,bundle,Scripting,Applescript,Bundle,如何捆绑包含从文件夹中随机读取脚本的主脚本的applescript?您的问题很清楚,但这里有一个脚本,可以从文件夹中随机加载脚本(如果文件夹中包含脚本) set theFolder to choose folder as string set theFiles to do shell script "ls " & quoted form of posix path of theFolder & " | grep '.scpt$' || true" if theFiles = ""

如何捆绑包含从文件夹中随机读取脚本的主脚本的applescript?

您的问题很清楚,但这里有一个脚本,可以从文件夹中随机加载脚本(如果文件夹中包含脚本)

set theFolder to choose folder as string
set theFiles to do shell script "ls " & quoted form of posix path of theFolder & " | grep '.scpt$' || true"
if theFiles = "" then return
set theFile to some item of (paragraphs of theFiles)
set randomScript to load script file (theFolder & theFile)
请检查以下代码:

它除了做其他事情外,还可以使用子程序来处理脚本

下面是一个完整的脚本,当您按照以下步骤操作时可以使用:将其另存为应用程序,并将所有脚本放入该应用程序的Resources文件夹中,如网页“Show Package Contents”中所述。祝你好运

property MyUserName : ""

if MyUserName is "" then

    display dialog "User Name:" default answer "" buttons {"Cancel", "Continue…"} default button 2
    copy the result as list to {returnedButton, returnedText}

    if returnedButton is "Cancel" then return

    -- What to do when the user did not input any text?
    if returnedText is "" then return -- we stop. 

    set MyUserName to returnedText
    say "Hello," & MyUserName & "!" using "Karen"

else

    display dialog "User name: " & MyUserName buttons {"Ok"} default button 1 with icon 1 giving up after 10

end if

say "For your information, please start the Amuse App everytime you log on... and I will speak to you at random times during your visit with me." using "Karen"

delay 20

try

    repeat 105 times

        set rnd to (random number from 1 to 105)
        set rndFileName to (rnd as text) & ".scpt"
        if my run_scriptfile(rndFileName) is false then -- if the script execution fails,…
            error number -128 -- … stop this app
        end if

    end repeat

on error the error_message number the error_number

    display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
    return

end try



on run_scriptfile(this_scriptfile)
    -- This handler will execute a script file 
    -- located in the Resources folder of this applet
    try
        set the script_file to path to resource this_scriptfile
        return (run script script_file)
    on error
        return false
    end try
end run_scriptfile
以下是您希望随机执行的3个脚本的外观:

有点混乱…我有一个随机读取脚本的脚本,我在问,你如何将主脚本和文件夹中的脚本捆绑在一起以制作applescript应用程序。将主脚本保存为应用程序,然后它就是一个捆绑包。您可以将其他脚本保存在捆绑包的资源文件夹中。请注意:带有扩展应用程序的应用程序文件夹是捆绑包。