I ended up creating my own: https://github.com/dtrebbien/Songs-Database-Viewer
In my case, the database is a simple database of songs, where each record has "Artist Name" and "Song Title" fields, so my Songs Database Viewer just has two columns for those fields. Though, Songs Database Viewer is adaptable to other schemas by adding more table columns in Interface Builder and setting the identifiers of the table columns to the field names.
Alternatively, a Database Events database is based on SQLite3, so the DBEV file can be opened with the command line sqlite3
utility. On Lion, the two important tables are ZRECORD
and ZFIELD
. Each row in ZRECORD
corresponds to a Database Events record and each row in ZFIELD
corresponds to a Database Events field.
The System Events process does not start at login, so the delay might be needed for some other reason. System Events also teriminates automatically if it is not used for a few minutes.
It probably won't help, but you could try launching System Events at the start of the script:
launch application "System Events"
You could also try using a launchd agent like this to launch a System Events process at login:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>
<plist version="1.0">
<dict>
<key>Label</key>
<string>test</string>
<key>Program</key>
<string>/System/Library/CoreServices/System Events.app/Contents/MacOS/System Events</string>
<key>RunAtLoad</key> <!-- run at login -->
<true/>
<key>KeepAlive</key> <!-- run the program again if the previous program terminates -->
<true/>
</dict>
</plist>
You can normally use something like tell application "System Events" to exists process "Finder"
to check if a process exists, but it obviously requires talking to System Events. In this case you might also use a shell script like this:
repeat 100 times
do shell script "ps -eco comm= | grep -x 'System Events'; exit 0"
if result is not "" then exit repeat
delay 0.1
end repeat
ps -e
is identical to -ax
(include processes from all users and processes without a controlling terminals), -c
prints command names instead of absolute paths in OS X, and -o comm=
prints only command names without the header row. You can replace the shell command with pgrep -x 'System Events'; exit 0
in 10.8 and later.
Best Answer
System Events is a faceless background app provided by Apple that gives AppleScript access to certain system functions and attributes. For example, we can use the app to change the desktop picture, control the user interface of other applications, change the screen saver, navigate the file system hierarchy, and more. Open Script Editor, choose File➔Open Dictionary..., and choose System Events from the list of apps. This will show you the AppleScript commands you can invoke.