By ZuluDeltaNiner

2012-12-15 04:33:56 8 Comments

I am more used to the Javascript style event handlers,

but is there a similar thing in applescript that listens to system events like logout or shutdown to execute code

or is there a way to have an applescript run on shutdown or logout?

I know about script timer but I would rather have something free.

All my script does is mute the volume for the next startup.


@Lri 2012-12-15 07:28:33

Logout hooks were deprecated in 10.4, but they still work in 10.8.

echo $'#!/usr/bin/osascript\n\nset volume with output muted' > ~/.logouthook
chmod +x ~/.logouthook
sudo defaults write LogoutHook ~/.logouthook

sudo defaults write modifies files in /var/root/Library/Preferences/. The program can't be inserted as an argument directly.

Trapping the exit signal only seems to work when logging out and not when shutting down.

@adayzdone 2012-12-15 05:12:45

Launch agents can be used for this. See this tutorial on MacScipter. If you are not familiar with the process, Lingon offers a simple interface to create the file. Here is an example to launch a script named ZuluDeltaNiner.scpt on login.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">

Related Questions

Sponsored Content

1 Answered Questions

[SOLVED] How might I save a variable between Applescript runs?

  • 2017-07-25 23:28:12
  • DonielF
  • 1285 View
  • 0 Score
  • 1 Answer
  • Tags:   applescript

2 Answered Questions

1 Answered Questions

1 Answered Questions

[SOLVED] In Applescript, how do I get a line number or stack trace on error?

  • 2016-04-13 12:33:51
  • Tim Baverstock
  • 386 View
  • 1 Score
  • 1 Answer
  • Tags:   applescript error

1 Answered Questions

[SOLVED] Problems creating OS X installer with AppleScript

1 Answered Questions

[SOLVED] How do I "say . . . using" in Javascript for Automation?

1 Answered Questions

[SOLVED] How to ask for a mail folder in applescript?

2 Answered Questions

[SOLVED] Need Help with an Applescript / plist

3 Answered Questions

[SOLVED] Applescript app to shut down Mathematica at a specific time of day

  • 2012-07-17 18:24:04
  • Jagra
  • 1102 View
  • 3 Score
  • 3 Answer
  • Tags:   applescript

Sponsored Content