Case in application identifier com.apple.Finder RuntimeErrors on raise or initialize #70

Open
Lucifer opened this Issue Jan 3, 2013 · 8 comments

3 participants

@Lucifer

Here's the output :-)

"com.apple.finder" works fine.

https://gist.github.com/4445579

@tbartelmess
Marketcircle Inc. member

The actual identifier is com.apple.finder, why should it be case insensitive?

@Lucifer

As com.apple.Finder still works but causes a RuntimeError when it should just fail as not found.

@ferrous26
Marketcircle Inc. member

The issue is that NSWorkspace.launchAppWithBundleIdentifier is case-insensitive, but NSRunningApplication.runningApplicationsWithBundleIdentifier is case-sensitive.

The problem then is that "com.apple.Finder" will not be found as a running application, so we try to launch it, which then brings Finder to the front (because it is already running). Then we sleep on the run loop for a couple of seconds and try again.

After looping a few times we raise an exception.

I think this might actually be an Apple problem...something to report to them. I just need to double check what I've claimed here first...

@Lucifer

Hey, we all make mistakes.....right?

Let me know then and I'll direct my gaze over to radar.

@Lucifer

Another example

1.9.3-p362 :003 > apple_contacts = AX::Application.new "com.apple.addressbook"
RuntimeError: com.apple.addressbook failed to launch in time
from /Users/mp4976qpa/Developer/AXElements/lib/accessibility/dsl.rb:136:in raise'
from /Users/mp4976qpa/Developer/AXElements/lib/ax/application.rb:134:in
initialize'
from (irb):3:in new'
from (irb):3
from /Users/mp4976qpa/.rvm/rubies/ruby-1.9.3-p362/bin/irb:16:in

'
1.9.3-p362 :004 > apple_contacts = AX::Application.new "com.apple.AddressBook"
=> #
1.9.3-p362 :005 >
1.9.3-p362 :006 > apple_contacts = AX::Application.new "com.apple.stupid"
RuntimeError: com.apple.stupid is not a registered bundle identifier for the system
from /Users/mp4976qpa/Developer/AXElements/lib/accessibility/dsl.rb:136:in raise'
from /Users/mp4976qpa/Developer/AXElements/lib/ax/application.rb:136:in
initialize'
from (irb):6:in new'
from (irb):6
from /Users/mp4976qpa/.rvm/rubies/ruby-1.9.3-p362/bin/irb:16:in
'

@tbartelmess
Marketcircle Inc. member

Here again, it's case sensitive. The identifier actually is com.apple.AddressBook. Probably it's best if you check the Info.plist of the application.

@ferrous26
Marketcircle Inc. member

Hmmm, that might have to be the work around for now. Fortunately, there are a few ways to easily get the bundle identifier for an application. Here's a non-exhaustive list of ways you can do it from within Ruby (with AXElements):

1: If the app is already running

AX::Application.new('Contacts').bundle_identifier

2: If you know where the app is:

load_plist(File.read('/Applications/Contacts.app/Contents/Info.plist'))['CFBundleIdentifier']
@ferrous26 ferrous26 was assigned Jan 12, 2013
@Lucifer

Thank-you, appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment