admin管理员组文章数量:1355617
I'll apologize upfront for posting another dang question/problem with an AppleScript shut down app. I must have read 1,000 threads relating to this topic.
Sequoia 15.3.2
2025 Apple M4 pro
I've pared down the code for my app to the basics and it has the same problems. The code follows:
on run
tell application "Finder" to activate
tell application "System Events" to set the visible of every process to true
try
tell application "Finder"
set listOfApps to name of every application process whose visible is true and name is not "Finder" and name is not "Script Editor" and name is not {name of me}
end tell
repeat with appToClose in listOfApps
tell application appToClose to quit without saving
end repeat
on error errStr number errorNumber
display dialog "errStr = " & errStr & return & "number = " & number & return & "errorNumber = " & errorNumber buttons {"Quit"} default button 1
return
end try
tell application "Finder" to close every window
tell application "System Events" to shut down
end run
If I comment out the "shut down" command, the code works fine in both the AppleScript Editor and as an app. If uncommented and run as an app, I get one of the following three results when I next boot.
- The computer immediately shuts down.
- The Apple -> Force Quit dialog shows my app name. ie. still running
- The following error appears on the desktop:
Any insights would be appreciated. Fairly new to AppleScript and I find it limited and frustrating.
I'll apologize upfront for posting another dang question/problem with an AppleScript shut down app. I must have read 1,000 threads relating to this topic.
Sequoia 15.3.2
2025 Apple M4 pro
I've pared down the code for my app to the basics and it has the same problems. The code follows:
on run
tell application "Finder" to activate
tell application "System Events" to set the visible of every process to true
try
tell application "Finder"
set listOfApps to name of every application process whose visible is true and name is not "Finder" and name is not "Script Editor" and name is not {name of me}
end tell
repeat with appToClose in listOfApps
tell application appToClose to quit without saving
end repeat
on error errStr number errorNumber
display dialog "errStr = " & errStr & return & "number = " & number & return & "errorNumber = " & errorNumber buttons {"Quit"} default button 1
return
end try
tell application "Finder" to close every window
tell application "System Events" to shut down
end run
If I comment out the "shut down" command, the code works fine in both the AppleScript Editor and as an app. If uncommented and run as an app, I get one of the following three results when I next boot.
- The computer immediately shuts down.
- The Apple -> Force Quit dialog shows my app name. ie. still running
- The following error appears on the desktop:
Any insights would be appreciated. Fairly new to AppleScript and I find it limited and frustrating.
Share Improve this question asked Mar 30 at 18:23 Uncle BillUncle Bill 637 bronze badges1 Answer
Reset to default 0Try this:
on run
delay 2
set keepAlive to {"Finder", "Script Editor", "killApp"} -- latter is name of this applet
tell application "System Events"
set openApps to name of (every process whose background only is false)
end tell
-- optional: list of open applications
set AppleScript's text item delimiters to linefeed
display dialog (openApps as text) with title "Open applications"
repeat with appn in openApps
if appn is not in keepAlive then
tell application appn to quit
end if
end repeat
end run
A couple of notes:
- You don't really need the Finder here. You can get the name property from System Events.
本文标签: shutdownApplescript shut down issuesStack Overflow
版权声明:本文标题:shutdown - Applescript shut down issues - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743978687a2570981.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论