I’m getting a puzzling error in an AppleScript application when it is first started and has to generate some items in the resource bundle. I’m running some UNIX shell scripts and store them in script resources. The script generates the scripts on the fly when first starting.
To make things simple (I thought) I have a handler called by the run handler that creates the folders and using UNIX touch to create empty file locations that are then filled out later. This allows me to use (path to resource . . .) in a uniform way no matter what state the script is in.
What is happening to me is that when the application is run the first time generates a “resource not found” error when the resources (empty files) do in fact exist. The effect is summarized in this code snippet:
-- Test Script to illustrate problem with getting "empty" resources -- First Create folder and empty files that will later be filled. set resourcePathStr to (path to me as string) & "Contents:Resources" set resourcePath to POSIX path of resourcePathStr -- Create Shell Scripts folder set shellScriptFolder to resourcePath & "/Shell Scripts" do shell script ("mkdir '" & shellScriptFolder & "'") -- Create empty files for the bash and SED scripts. set bashSEDscript to shellScriptFolder & "/SED_tag_processor.sh" do shell script ("touch '" & bashSEDscript & "'") set sedCommandFile to shellScriptFolder & "/LWC_AppleScript_tags.sed" do shell script ("touch '" & sedCommandFile & "'") -- These calls generate "resource not found" errors in larger script set bashSEDscript to POSIX path of (path to resource "SED_tag_processor.sh" in directory "Shell Scripts") set sedCommandFile to POSIX path of (path to resource "LWC_AppleScript_tags.sed" in directory "Shell Scripts")
If you run this script as a script bundle - it works just fine. However, if you save it as an application - it will generate the “resource not found error” I’m running into.
I’ve worked around the problem by getting the path in the same way I use to touch the file in the first place, but it is annoying. Am I doing something silly? Is there a “more better” way to deal with bundle resources that will exist but may not exist when the application is first run?
Thanks in advance for your help!
Model: MacBook Pro
Browser: Firefox 10.0
Operating System: Mac OS X (10.6)