Is there a way to retrieve the Application Identifier (that is set in the build options) at runtime?
Something like App.AppID?
dim file as FolderItem = App.ExecutableFile.Parent.Parent.Child("Info.plist")
dim b as BinaryStream = BinaryStream.Open(file, False)
dim s as String = b.Read(b.Length)
dim bundleID as String = NthField(s, "CFBundleIdentifier</key>", 2)
bundleID = NthField(bundleID, "<string>", 2)
bundleID = NthField(bundleID, "</string>", 1)
MsgBox bundleID
Cool, that will work.
Thanks Axel!
FYI, this assumes the file uses the xml format, which may not be true.
huh
this would be the best answer but it looks like it got broke along the way
with Applescript
dim file as FolderItem = App.ExecutableFile.Parent.Parent.Parent
if file <> nil and file.Exists then
dim sh as new shell
dim cmd as String
cmd = "osascript -e 'id of app " + """" + file.NativePath + """" + "'"
sh.Execute cmd
MsgBox sh.Result
end if
[quote=224305:@Norman Palardy]huh
this would be the best answer but it looks like it got broke along the way
<https://xojo.com/issue/30710>[/quote]
Ah no
Add a constant to the App instance - called ID
Set its value to “com.mycompany.myapp”
In the OS X setting put in #App.ID for the bundle ID
Build & off you got
The constant is your bundle id
Done
For future searches:
Dim appId As String
#If TargetMacOS
Declare Function mainBundle Lib "AppKit" selector "mainBundle"(NSBundleClass As Ptr) As Ptr
Declare Function NSClassFromString Lib "AppKit"(className As CFStringRef) As Ptr
Declare Function getValue Lib "AppKit" selector "bundleIdentifier"(NSBundleRef As Ptr) As CFStringRef
appId = getValue(mainBundle(NSClassFromString("NSBundle")))
#EndIf
If you use TPSF you can get the bundle identifier thanks to Sam.
Are you talking about getting your OWN bundle ID ?
If so just set a constant IN your source code and refer to that
Add a constant to the App instance - called ID
Set its value to “com.mycompany.myapp”
In the OS X settings put in #App.ID for the bundle ID
Now anywhere in your code you can just refer to App.ID
The constant is your bundle id
Want to change your bundle ID ?
Change the constant & recompile