I’m trying to include a .txt within my AppleScriptobjc Xcode project but didn’t found the way to do it in case that it is possible.
My intention is to bundle it and create a standalone application that does not have the necessity of look for any external resource outside the application.
In case that it possible I’d much appreciate to know what are the steps I should follow to integrate it and how to reference it.
I have not bundle the application yet since I’m still developing it.
I tried different things following your steps but with no success.
When I drag the .txt into the project folder I’m prompt to select a
[format]‘Destination’: Copy items if needed (I check it)
‘Added folders’: (I check Create folder references)
‘Add to targets’: (I check my project)[/format]
And here it is the code I’ve used in the AppDelegate file to test it:
set theFile to current application's NSBundle's mainBundle()'s pathForResource:"MyFile" ofType:"txt"
display dialog theFile
# It yields "msng"
set theFile to theFile as «class furl»
set theFileList to paragraphs of (read theFile as «class utf8»)
# But I received the following error message:
Can’t make missing value into type «class furl». (error -1700)[/AppleScript]
Thank you in advance.
Marius
If you have an AppleScriptobjc Xcode project you do have a bundle.
Don’t check Create folder references. Delete the file and the enclosing folder (in Xcode) and add the file again.
Of course “MyFile” must match the file name in the bundle. And use the Cocoa API to read the file
property |⌘| : a reference to current application
set filePath to |⌘|'s NSBundle's mainBundle()'s pathForResource:"MyFile" ofType:"txt"
set theText to (|⌘|'s NSString's stringWithContentsOfFile:filePath encoding:(|⌘|'s NSUTF8StringEncoding) |error|:(missing value)) as text
set theParagraphs to paragraphs of theText
When I started my project, it was only based in vanilla AppleScript and then I realized that at least a basic knowledge of Object C and now COCOA API is necessary to go ahead with the features I want to have my app.
Tomorrow is a day off for me, so I will be digging in into the ‘Everyday AppleScriptObjC 3ed’ I’ve just get.