Want to use Microcosm’s “Play Sound” to play a wav file which will reside within my script bundle’s “Resources” folder.
I’m a little weak on the “path” concept. Will I need to point my script at the sound file (ie create a fixed path), or is there a simpler way if it resides at the same level as the script?
Something makes me think the fixed path is the wrong way to go, but like I said, I’m weak on this.
Different methods of getting the path to a resouce in a bundle…
Most compatible:
set theResource to ((path to me as Unicode text) & "Contents:Resources:filename") as alias
--> alias
Only on Mac OS X 10.4 or later:
set theResource to (path to resource "filename")
--> alias
Um,
Sorry for being slow on the uptake…
but this isn’t working: (“Resource not found”)
set theResource to (path to resource "cartoonskid.wav")
Hi,
consider, that path to resource doesn’t work in Script Editor.
You have to run the script directly
What do you mean, “run the script directly?”
don’t run it in Script Editor, save it as application and run the app
Sigh.
I’m sorry for this;
when I run the app… do I need to make it a droplet? (Else how will it know which “Contents” folder I’m talking about?)
applet or droplet doesn’t matter (the difference is only, a droplet must have an open handler, and an applet must have a run handler)
path to resource points always to the folder /Contents/Resources of the applet/droplet itself
So, you’re saying put
set theResource to ((path to me as Unicode text) & “Contents:Resources:filename”) as alias
inside the original script?
like this:
on getpath
set theResource to ((path to me as Unicode text) & “Contents:Resources:filename”) as alias
end
yes, look at Bruce’s post
But the script must be saved as application bundle
OK, I’m getting somewhere…
saved as an app bundle, but it still can’t see the wav file.
The error log says
file
MAC:Users:mainuser:Desktop:AutoPrint.app:Contents:Resources:cartoonskid.wav wasn’t found
anyone see what’s tripping me up?
It might be an terminology conflict.
For example (script is an application bundle):
tell application "QuickTime Player"
open (path to resource "welcome.wav")
play movie 1
end tell
causes QuickTime Player got an error: Resource not found.
this works:
set soundfile to path to resource "welcome.wav"
tell application "QuickTime Player"
open soundfile
play movie 1
end tell
But don’t I need to tell it (roughly) WHERE to look for the resource?
It still can’t find it, even with your new code; get “Resource not found” error now
Wouldn’t it be easier to post the whole crucial portion of the code? 
You got it: (and thanks for working on this)
set soundfile to path to resource "cartoonskid.wav"
tell application "QuarkXPress"
tell document 1
try
set boxList to object reference of every text box of every page whose box overflows is true
on error
set boxList to {}
end try
if boxList's length > 0 then
select (first item of boxList)
show selection
tell application "Play Sound"
play theSound
end tell
else
display dialog "You're Clean"
try
print with print dialog
end try
end if
end tell
end tell
Just so you know, its a Quark X script to catch any overflowing text…
hm, you set the variable soundfile but you play the variable theSound
Yeah, good point, but I can’t even get past the first line…
Again, are you running your script by double clicking it in the Finder
and NOT in Script Editor?
Path to resource doesn’t work in Script Editor
Double-clicking, as you said…
maybe I should look at another person’s script who’s done this. I seem to be missing something fundamental…
Try this:
Comment out the whole script,
paste the following and tell me, what happens,
it should display all filenames of the folder Resources.
Please run the script again from the Finder
set s to (path to me as Unicode text) & "Contents:Resources:"
tell application "Finder" to set n to name of files of folder s
set {TID, text item delimiters} to {text item delimiters, return}
set n to n as Unicode text
set text item delimiters to TID
display dialog n