htdefiant Posted April 27, 2008 Share Posted April 27, 2008 Hello all, I am brand new to AppleScripting, but I don't have the time to dedicate right now to actually learning the language - I just need to get one script done. Here is what it needs to do: 1. Once the program is launched, a 16 second audio clip will play. 2. All currently running programs will be forced to quit with no save options. 3. The computer will be shut down. Seeing as I have literally never scripted before, what do you think the best way of going about this is? Thanks Link to comment https://www.insanelymac.com/forum/topic/101736-simple-applescript-help/ Share on other sites More sharing options...
thePixeler Posted April 30, 2008 Share Posted April 30, 2008 AppleScript by itself can't play audio files. Would it be OK it QuickTime played the audio clip? Or you could use something like Play Sound. Link to comment https://www.insanelymac.com/forum/topic/101736-simple-applescript-help/#findComment-730136 Share on other sites More sharing options...
htdefiant Posted April 30, 2008 Author Share Posted April 30, 2008 I'd rather not use PlaySound, only because I want this script to be able to run on more then just my Mac. Would making this an application be better? Link to comment https://www.insanelymac.com/forum/topic/101736-simple-applescript-help/#findComment-730609 Share on other sites More sharing options...
thePixeler Posted April 30, 2008 Share Posted April 30, 2008 What about QuickTime? Every Mac has QuickTime installed. Or do you not want the user to see the QuickTime window. if you don't, then making a Cocoa app is the only way I can think of that will do what you want. Link to comment https://www.insanelymac.com/forum/topic/101736-simple-applescript-help/#findComment-730826 Share on other sites More sharing options...
htdefiant Posted April 30, 2008 Author Share Posted April 30, 2008 Quicktime would be acceptable, I think. Link to comment https://www.insanelymac.com/forum/topic/101736-simple-applescript-help/#findComment-730845 Share on other sites More sharing options...
thePixeler Posted May 1, 2008 Share Posted May 1, 2008 OK then use this script. set audioFile to "/path/to/your/audio/file.mp3" tell application "QuickTime Player" activate open audioFile end tell tell application "Finder" set visible of process "QuickTime Player" to false end tell delay 16 tell application "System Events" set theProcesses to every process whose visible is true and name is not "Finder" and name is not (name of me) end tell repeat with i from 1 to (count of theProcesses) set thisProcess to item i of theProcesses try tell application (name of thisProcess) to quit without saving end try end repeat tell application "Finder" to shut down Don't forget to edit the first line to point to the audio file you want QuickTime to play and to save it as an application. Link to comment https://www.insanelymac.com/forum/topic/101736-simple-applescript-help/#findComment-731903 Share on other sites More sharing options...
htdefiant Posted May 1, 2008 Author Share Posted May 1, 2008 Hey, The file did not autoplay, Quicktime player just opened. When I manually played the file to its completion, the computer did not shut down. Thanks for your help Link to comment https://www.insanelymac.com/forum/topic/101736-simple-applescript-help/#findComment-732248 Share on other sites More sharing options...
thePixeler Posted May 3, 2008 Share Posted May 3, 2008 Try using this. set audioFile to "/path/to/your/audio/file.mp3" tell application "QuickTime Player" activate open audioFile play the front document end tell tell application "Finder" set visible of process "QuickTime Player" to false end tell delay 16 tell application "System Events" set theProcesses to every process whose visible is true and name is not "Finder" and name is not (name of me) end tell repeat with i from 1 to (count of theProcesses) set thisProcess to item i of theProcesses try tell application (name of thisProcess) to quit without saving end try end repeat tell application "Finder" to shut down What OS are you running? Also note that the computer will only shutdown if you save this script as an application and run the app. If you just click "Run" in Script Editor it wont work. Link to comment https://www.insanelymac.com/forum/topic/101736-simple-applescript-help/#findComment-733523 Share on other sites More sharing options...
htdefiant Posted May 3, 2008 Author Share Posted May 3, 2008 Leopard 10.5.2. I will try this when I return to my Mac. Link to comment https://www.insanelymac.com/forum/topic/101736-simple-applescript-help/#findComment-734066 Share on other sites More sharing options...
htdefiant Posted May 3, 2008 Author Share Posted May 3, 2008 I got it to work, once. However, when I wanted to show a friend, running the application for the second time, the Quicktime file failed to autoplay. Also, the Quicktime browser windows opened. Thanks. Link to comment https://www.insanelymac.com/forum/topic/101736-simple-applescript-help/#findComment-734185 Share on other sites More sharing options...
thePixeler Posted May 3, 2008 Share Posted May 3, 2008 I works fine for me. AppleScript is can be so picky sometimes. Try this one. set audioFile to "Macintosh HD:Users:yourUserName:pathTo:theAudioFile.aif" as alias tell application "Finder" to set theName to (name of audioFile) tell application "QuickTime Player" activate open audioFile play document theName end tell delay 16 tell application "System Events" to set theProcesses to every process whose visible is true and name is not "Finder" and name is not (name of me) repeat with i from 1 to (count theProcesses) set thisProcess to item i of theProcesses try tell application (name of thisProcess) to quit without saving end try end repeat tell application "Finder" to shut down Link to comment https://www.insanelymac.com/forum/topic/101736-simple-applescript-help/#findComment-734338 Share on other sites More sharing options...
htdefiant Posted May 3, 2008 Author Share Posted May 3, 2008 Got it working. Now is there anyway to export it so that it includes the audio file (so I don't have to have the file sitting on my desktop)? In other words, is there any way to make this a packaged app? Link to comment https://www.insanelymac.com/forum/topic/101736-simple-applescript-help/#findComment-734395 Share on other sites More sharing options...
thePixeler Posted May 3, 2008 Share Posted May 3, 2008 Yes there is. Change the top line in the script to this… set audioFile to ((path to me as string) & "Contents:Resources:" & "audioFile.aif") as alias When you save the script select "Application bundle" as the file format. In the Finder, right click the newly saved app and select "Show Package Contents". Navigate to "Contents>Resources" and place your audio file there (inside the "Resources" folder). Now it's self contained. Link to comment https://www.insanelymac.com/forum/topic/101736-simple-applescript-help/#findComment-734479 Share on other sites More sharing options...
htdefiant Posted May 3, 2008 Author Share Posted May 3, 2008 OK, the program now reads: set audioFile to ((path to me as string) & "Contents:Resources:" & "audio.wav") as alias tell application "Finder" to set theName to (name of audioFile) tell application "QuickTime Player" activate open audioFile play document theName end tell delay 16 tell application "System Events" to set theProcesses to every process whose visible is true and name is not "Finder" and name is not (name of me) repeat with i from 1 to (count theProcesses) set thisProcess to item i of theProcesses try tell application (name of thisProcess) to quit without saving end try end repeat tell application "Finder" to shut down However, when I launch it, it says "CAn't get document "audio.wav" of application "Quicktime Player". Oddly, once I click OK on that error message, the file is present (not autoplaying) and I can press play manually. The script aborts though. ' Link to comment https://www.insanelymac.com/forum/topic/101736-simple-applescript-help/#findComment-734512 Share on other sites More sharing options...
thePixeler Posted May 3, 2008 Share Posted May 3, 2008 Hmm.... OK. Try adding a one or two second delay between the open command and the play command. So it'll look like this. open audioFile delay 2 play document theName Link to comment https://www.insanelymac.com/forum/topic/101736-simple-applescript-help/#findComment-734537 Share on other sites More sharing options...
htdefiant Posted May 3, 2008 Author Share Posted May 3, 2008 Still getting the same error. Link to comment https://www.insanelymac.com/forum/topic/101736-simple-applescript-help/#findComment-734635 Share on other sites More sharing options...
thePixeler Posted May 4, 2008 Share Posted May 4, 2008 Argh. And you though this was going to be easy. OK 6th time's the charm. Replace the whole QuickTime tell block with this new one. tell application "QuickTime Player" activate open audioFile set openDocuments to 0 set timer to 0 repeat while (count openDocuments) < 2 and timer < 10 set openDocuments to the name of every document repeat with i from 1 to (count openDocuments) play document (item i of openDocuments) end repeat set timer to (timer + 1) delay 1 end repeat end tell Link to comment https://www.insanelymac.com/forum/topic/101736-simple-applescript-help/#findComment-734689 Share on other sites More sharing options...
htdefiant Posted May 4, 2008 Author Share Posted May 4, 2008 Error: Can't get document "promo.mov" of application "Quicktime Player". Audio does play though. Seems to be a problem with the Quicktime Guide that launches. If you can get the content guide not to load, this might work. 7th time? Link to comment https://www.insanelymac.com/forum/topic/101736-simple-applescript-help/#findComment-734696 Share on other sites More sharing options...
thePixeler Posted May 4, 2008 Share Posted May 4, 2008 Does the content guide at least close now? tell application "QuickTime Player" activate delay 2 set openDocuments to (every document) repeat with i from 1 to (count openDocuments) close (item i of openDocuments) end repeat open audioFile play document "audio.wav" end tell Link to comment https://www.insanelymac.com/forum/topic/101736-simple-applescript-help/#findComment-734706 Share on other sites More sharing options...
htdefiant Posted May 4, 2008 Author Share Posted May 4, 2008 Error: Can't get document "audio.wav" of application "Quicktime Player". Guide closed though. Link to comment https://www.insanelymac.com/forum/topic/101736-simple-applescript-help/#findComment-734752 Share on other sites More sharing options...
thePixeler Posted May 4, 2008 Share Posted May 4, 2008 Replace: play document "audio.wav" With: play the front document If that doesn't work then I'm out of ideas. Maybe your computer is cursed, I dunno. Link to comment https://www.insanelymac.com/forum/topic/101736-simple-applescript-help/#findComment-734799 Share on other sites More sharing options...
htdefiant Posted May 4, 2008 Author Share Posted May 4, 2008 It lives! Thank you very much for your help. Link to comment https://www.insanelymac.com/forum/topic/101736-simple-applescript-help/#findComment-735479 Share on other sites More sharing options...
Recommended Posts