I’m trying to make a little mini-app that plays an AIFF on startup. I have no idea how to though. Just the basic code would be nice. I’m a clueless Applescript n00b.
Dear mbias_macs,
In OS/X, simply click on "Login Items" in System Preferences, and when that window appears, click the "Add" button, choose a sound file for your startup jingle, make sure that the checkbox to your far left is left UNchecked, and then quit Login Items. This should work nicely.
Sincerely,
Variable as the shade
I presume that will open the file in whatever viewer is defined for it? That means it will load Quicktime Player and potentially leave it open maybe?
You are most likely correct. As far as I know, you’ll need additional software to (invisibly) play an AIFF file. Extra Suites, a faceless application, can do this and much more.
– Rob
OK Extra Suites specifies the command structure as:
play AIFF alias – file path as alias
So how do i format my line of code?
tell application "Extra Suites"
play AIFF alias "path:to:my.aiff"
end tell
– Rob
That works, but…
I’m not paying for Extra Suites just to do that
I have this so far:
tell application "Finder"
open file "<file path>"
end tell
tell application "QuickTime Player"
play
close
end tell
This succesfully opens the file in QTP but i can’t get it to play it. Any ideas?
Will ‘close’ close QTP after?
So those two last bits right will make it do the job for free
Tip: QuickTime Player is recordable. This means that you can press the record button in a Script Editor window and then manually perform the task in QuickTime Player. When you are finished, go back to Script Editor and press the stop button. The result should be the code that you need to finish your script.
– Rob
This should work:
tell application "QuickTime Player"
set the_movie to open ("Path:to:file" as alias)
play the_movie
repeat
if done of the_movie = true then exit repeat
delay 1
end repeat
quit
end tell
Jon
Ooh, I wondered why it would quit before the sound even finished playing…
well, dangit, I’ll add your repeat loop to the app I made and brb…
Hmm, when I try putting that into an Xcode script, it interprets done as a variable. I haven’t run it yet, but I’m assuming I’ll get a not defined error. Any idea how I could implement that type of repeat loop to determine when the sound has finished playing in an ASS application? I’ve just did a quick app in Xcode with the following code:
using terms from application "Xcode"
-- Jingle.applescript
-- Jingle
-- Created by Mark Douma on Sun Jan 18 2004.
-- Copyright (c) 2004 Mark Douma. All rights reserved.
on launched theObject
set the_sound_ to load sound "sound"
play the_sound_
repeat
if done of the_sound_ = true then exit repeat
delay 1
end repeat
--delay 10
delete the_sound_
quit me
return
end launched
end using terms from
I’ve set the LSUIElement of the app to 1 so it runs invisibly, and it holds the sound in the /Contents/Resources/ folder inside the application bundle. As you can see, I had “delay 10” before, but it’d be nice to let it work for any length sound file.
Thanks in advance…
No “done” is a property native to QuickTime Player. Is there some reason you are creating a new app just to play a sound as opposed to using QuickTime Player (using the fully formed script above saved as an application and added to your Startup Items)?
Jon
I just figured it’d be more of what he was looking for, especially since it’ll run invisibly and be self-contained. And I’m also trying to learn AppleScript Studio.
I just checked the AppleScriptKit.asdictionary and saw that “playing” was a property of the “movie view” class. Changing “done” to “playing” and “true” to “false” in the script worked:
using terms from application "Xcode"
-- Jingle.applescript
-- Jingle
-- Created by Mark Douma on Sun Jan 18 2004.
-- Copyright (c) 2004 Mark Douma. All rights reserved.
on launched theObject
set the_sound_ to load sound "sound"
play the_sound_
repeat
if playing of the_sound_ = false then exit repeat
delay 1
end repeat
delete the_sound_
quit me
return
end launched
end using terms from
Jingle.sit (.sitx, ~100 KB)
You can customize the sound you want to play by replacing the default sound that’s inside Jingle’s application bundle. To do so, select Jingle in the Finder, Control-click on it and choose “Show Package Contents” from the popup menu. In the new window that appears, look inside the /Contents/Resources/ folder for the “sound.aiff” sound file. Take the sound file you’d like to use, rename it to “sound.aiff” and copy it into the /Contents/Resources/ folder, replacing the original one that was there.
Jeee - err thanks. I kinda wasn’t expecting someone to write it for me! Still it does the job perfectly. Thank you.
you can also use Play Sound:
http://www.versiontracker.com/dyn/moreinfo/macosx/14017
It’s a scripting addition but needs the tell block something like this:
tell application “Play Sound”
play alias “Macintosh HD:Users:kel:Desktop Projects:Frog.aiff”
end tell
Correction: it’s not a scripting addition, but a background app.
gl,