Hi,
I have written a script that allows a user to input data and then place that data into a TextEdit document using a search and replace routine. Now that I’m happy with my script I wanted to embed the original TextEdit document that has the search and replace performed on it into my script. I’ve darg and dropped the file into contents window of the bundle but when I tell TextEdit to open this file it can’t find it. I thought I must be specifying the wrong path but if I change the application to BBEdit the file opens without any problems. Please help!!!:mad:
set mainFile to "/Users/nik/Desktop/Digital Ads Stuff/Untitled.scptd/Contents/Resources/thetextfile.txt"
tell application "TextEdit" --if I change this app to BBEdit the file opens
open mainFile
end tell
AppleScript works only with colon delimited paths,
slash delimited paths will be used for “do shell script” commands.
There is a very easy way to access files in the resources folder of an application bundle
with the command “path to resource”. But it works only when started from the application bundle,
not in Script Editor, which refers to itself (Script Debugger can handle it properly)
set mainfile to path to resource "thetextfile.txt" as string
tell application "TextEdit" --if I change this app to BBEdit the file opens
open mainfile
end tell
That worked a wonderfully. It’s the first time I’ve tried to embed files into a script but now I know how, this has opened many more doors for my scripts.
Thanks very much for your help Stefan.