- let bundle_identifier = NSString::alloc(nil).init_str("com.spotify.Client");
- let app: *mut Object = msg_send![cls, applicationWithBundleIdentifier:bundle_identifier];
- Id::from_ptr(app)
+ let bundle_identifier = NSString::alloc(nil).init_str("com.spotify.Client");
+
+ let workspace_class = Class::get("NSWorkspace").unwrap();
+ let shared_workspace: id = msg_send![workspace_class, sharedWorkspace];
+ let app_url: id = msg_send![shared_workspace, URLForApplicationWithBundleIdentifier:bundle_identifier];
+
+ if app_url != nil {
+ let app: *mut Object =
+ msg_send![cls, applicationWithBundleIdentifier:bundle_identifier];
+ Id::from_ptr(app)
+ } else {
+ return None;
+ }