-- StartMeUpTakeMeDown 1.0, Script by Oskar Lindell -- Mounts a disk image (named DiskImage.dmg) found in the same directory as the script -- Changes display resolution to 640x480 if command file cscreen is found in the same directory as the script -- Opens application (named MainApp.app) found in the same directory as the script -- Waits for application to quit -- Unmounts the disk image -- Restores previous display resolution, if needed -- Possible future work with this script: -- 1. Make it possible to change screen resolution to other resolutions besides 640x480 -- 2. Make it possible to automatically mount more than one disk image (named DiskImage1.dmg, DiskImage2.dmg and so on) -- 3. Make the restoration of screen resolution and tmp-file cleanup a process of its own so that it will run even if this script/process crashes. Is it possible? -- 4. Cleanup this code -- Get path to running script set PathToScript to (path to me) as string -- Get path to the directory that the script (and application files) reside in tell application "Finder" set WorkPath to (container of item PathToScript) as text end tell -- Get PosixPath, same as WorkPath but POSIX compliant set PosixPath to quoted form of POSIX path of WorkPath -- Checks to see if the command cscreen exists in current directory. If it does, this script will change display resolution to 640 x 480 when running application. tell application "Finder" if (exists item "cscreen" of the container of (path to me)) then set ChangeRes to true -- Get current display resolution and depth set i to 14 set d to words of (do shell script PosixPath & "cscreen -l") set DisRecord to {DDepth:item (i + 1) of d, DWidth:item (i + 2) of d, DHeight:item (i + 3) of d} -- Set screen resolution to 640 x 480 do shell script PosixPath & "cscreen -x 640 -y 480" else set ChangeRes to false end if end tell -- Get unique process number for tmp-file set ProcessNumber to do shell script ("echo $$") -- Mount Disk Image in current folder (must be named DiskImage.dmg) and put the Disk's volume path(s) in tmp-file do shell script ("hdiutil attach " & PosixPath & "DiskImage.dmg -mount required -noverify 2>&1 >/tmp/volumepath_" & ProcessNumber) -- Start Main Application in current folder (must be named MainApp.app) set MainApp to WorkPath & "MainApp.app" activate application MainApp -- Wait until Application has quit set HasQuit to false repeat until HasQuit is true tell application "System Events" if exists process "MainApp" then delay 1 else set HasQuit to true end if end tell end repeat -- Restore previous display resolution and depth, if needed if ChangeRes is true then do shell script PosixPath & "cscreen -d " & DDepth of DisRecord & " -x " & DWidth of DisRecord & " -y " & DHeight of DisRecord end if -- Unmount Disk Image set VolumePath to do shell script ("grep ^/dev/disk /tmp/volumepath_" & ProcessNumber & " | cut -d' ' -f1 | head -n1") do shell script "hdiutil unmount " & VolumePath & " -force -quiet" do shell script "hdiutil detach " & VolumePath & " -force -quiet" -- Cleanup tmp-files do shell script "rm -f /tmp/volumepath_*" --- THE END ---