如何捆绑一个带有主脚本的AppleScript,该脚本从文件夹中随机读取脚本?
答案 0 :(得分:0)
您的问题很明确但是这里有一个脚本,可以从文件夹中随机加载一个脚本,如果该文件夹包含任何脚本。
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)
答案 1 :(得分:0)
查看此代码:http://macosxautomation.com/applescript/linktrigger/index.html。
它正是这样做(除了其他东西),你可以使用那里的子程序进行脚本处理。
这是一个完整的脚本,当您按照以下步骤操作时:将其保存为应用程序并将所有脚本放入该应用程序的“Resources”文件夹中(如网页“显示包内容”中所述)。祝你好运。
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个脚本的外观: