Hi, my application doesn’t seem to like these two lines of code.
log (POSIX path of (path to me))
display dialog (POSIX path of (path to me)) buttons {"OK"}
It can’t log or display a dialog showing the POSIX path to my application.
The error I get is
Any help as to why I get this error and how to fix it?
Model: MacBook Pro 2.53 GHz
AppleScript: 2.1.2
Browser: Firefox 4.0b6
Operating System: Mac OS X (10.6)
StefanK
November 1, 2010, 5:24pm
#2
Hi,
it looks like you’re using this lines within an application (or whatever) tell block, which causes some terminology clash.
As you’re dealing with AppleScriptObjC anyway I’d prefer
current application's NSBundle's mainBundle()'s bundlePath()
Thanks, on it’s own it works, I’ve been testing various things just by logging them, when I try this:
log (current application's NSBundle's mainBundle()'s bundlePath()) & "/Contents/Info.Plist"
I get an error:
Can't make «class ocid» id «data kptr00000000C00E010002000000» into type list, record or text. Error number -1700.
StefanK
November 1, 2010, 5:42pm
#4
try this
log (current application's NSBundle's mainBundle()'s bundlePath()) as text & "/Contents/Info.Plist"
or
current application's NSBundle's mainBundle()'s bundlePath()'s stringByAppendingPathComponent_("Contents/Info.plist")
Thanks, I’m trying to read my application’s Info.plist but I’m failing a bit here… code:
set infoPlist to (current application's NSBundle's mainBundle()'s bundlePath()'s stringByAppendingPathComponent_("Contents/Info.plist"))
display dialog (do shell script "defaults read " & infoPlist & " script1")
The error I get is:
StefanK
November 1, 2010, 6:07pm
#6
/usr/bin/defaults expects the path without the path extension
This should work without the shell
set infoPlistScript1 to (current application's NSBundle's mainBundle()'s bundlePath()'s objectForInfoDictionaryKey_("script1")) as string
display dialog infoPlistScript1
StefanK:
/usr/bin/defaults expects the path without the path extension
This should work without the shell
set infoPlistScript1 to (current application's NSBundle's mainBundle()'s bundlePath()'s objectForInfoDictionaryKey_("script1")) as string
display dialog infoPlistScript1
Unfortunately, this gives me an error:
and
StefanK
November 1, 2010, 6:20pm
#8
sorry, omit bundlePath()'s
set infoPlistScript1 to (current application's NSBundle's mainBundle()'s objectForInfoDictionaryKey_("script1")) as string
Now it displays a dialog saying “missing value” when actually it’s set to “/Applications” (just to test)
StefanK
November 1, 2010, 6:30pm
#10
the standard info.plist file doesn’t contain a key “/Applications”,
most of the standard keys begin with CFBundle. Try for example “CFBundleVersion”
I’ve added a new key in, it’ll have a path in it. Just while I’m getting the code to work and testing, I’ve set the path to /Applications
StefanK
November 1, 2010, 6:56pm
#12
the method “get value of key of infoDictionary of main bundle” is the normal Cocoa way to read info.plist.
Does this work
set infoPlist to (current application's NSBundle's mainBundle()'s bundlePath()'s stringByAppendingPathComponent_("Contents/Info")) as string
display dialog (do shell script "defaults read " & infoPlist & " script1")
StefanK:
sorry, omit bundlePath()'s
set infoPlistScript1 to (current application's NSBundle's mainBundle()'s objectForInfoDictionaryKey_("script1")) as string
I had this code in like you said, I was pretty sure it didn’t work. Just tried it and it does, really sorry about that! :S Thanks for all the help!