OS X: How can I forward contextual menu clicks from dock icon to another application? - objective-c

Question: Is there any way for one app to programmatically access and activate the contextual menu items that can be accessed when right clicking on the dock icon of another application?
App A: Non-open source Mac App Store app that currently has no AppleScript support
App B: My own application, which I could write in Objective-C, AppleScript, Python, whatever...
When I right click on the dock icon for App A, I see contextual menu options for custom commands related to the function of that application. What I would like to do is to populate the contextual menu for App B with the same commands, which when accessed forward those commands to App A assuming that App A is open (even if its dock icon is hidden).
Is this sort of thing possible?

Here's an idea. Download LiveCode 6.6.1 (the version of which I know that it all works) and add a button to a new LiveCode document. Select the button and press command-E to edit the script. Enter the following synax (for testing):
on mouseUp
put "test" & cr & tab & "test1" into myMenu
set the iconMenu to myMenu
end mouseUp
on iconMenuPick theItem
if theItem contains "test1" then
answer "You chose" && theItem
end if
end iconMenuPick
This is useful, because you can also use AppleScript and GUI scripting with LiveCode. Let LiveCode be app B and have it control app A.

Related

How to set custom icon for file-type in mac osx

I have a launcher application for some file-types in mac osx. I want to know is it possible to register custom Icon for file-types associated with my launcher application? and does anybody know exact behavior of OS, when does it show Icon and when does it show some empty icon?
Question 1:
It's easy. In finder, right click on the filename with the extension you're interested in.
Find the "Open with:" section,
Click on the blue part and navigate to your launcher app and select it.
Then click on "Change All..."
Write down, or remember what it used to be before changing it, in case you want to go back to the old behavior. It affects all files with that extension.
Question 2:
Check this link for information on filling in the images in your assets folder: App Icons
If you include an icon in your app, and do the above steps, the icon will show. If you don't include one, it won't.

How to enable "Private Browsing" in Safari (Mac) and open a new link? Scripting Bridge

I'm currently trying to enable "Private Browsing" in Safari for Mac, through Scripting Bridge but without any success. The following code shows how to do the same thing, but for Google Chrome (creating a new window with incognito mode enabled and opening a new link):
chromeBrowser = [SBApplication applicationWithBundleIdentifier:#"com.google.Chrome"];
ChromeWindow *window = [[[chromeBrowser classForScriptingClass:#"window"] alloc] initWithProperties:#{#"mode": #"incognito"}];
[chromeBrowser.windows addObject:window];
ChromeTab *tab = [window.tabs firstObject];
tab.URL = url;
[chromeBrowser activate];
But, unfortunately, Safari works a little different comparing to Chrome. Each Chrome's window works separately in terms of "private browsing" (incognito). In Safari, when you enable the the "private browsing", the whole application will reflect that option, not just a particular window. Any ideas on how to do that, using Scripting Bridge or something similar? Thanks!
Safari's AppleScript dictionary doesn't give you access to Private Browsing mode, so there's no way to do it directly in Scripting Bridge.
You could do it with an NSAppleScript using System Events, like this:
tell application "Safari"
set menuItemName to localized string "Private Browsing …"
end tell
tell application "System Events" to tell process "Safari"
if menu item menuItemName of menu 1 of menu bar item 2 of menu bar 1 exists then
click menu item menuItemName of menu 1 of menu bar item 2 of menu bar 1
keystroke return
else
click menu item menuItemName of menu 1 of menu bar item 2 of menu bar 1
end if
end tell
System Events scripting can't be done via Scripting Bridge, and it's slower and flakier than scripting an application directly, but it might be your best option. If you go this route, make sure your cross-scripting entitlement includes the bundle ID for the System Events application.

Menu bar button panels in Cocoa?

When I click on buttons in the menu bar (such as "About Program") when the program is running a new window pops up displaying information. How do I edit the windows associated with the buttons?
In Interface builder I manage to load "Main Menu" which allows me to customize the menu bar, but it doesn't allow me to work with the windows associated with the buttons. How would I edit these windows?
Mac OSX Snow Leopard, Xcode 3.2.6
EDIT: I am not specifically asking for steps for the "About Panel". I am looking for a general procedure for editing panels associated with buttons in the menu bar. In addition to the "About" panel I would also want to work with panels such as the "Help" panel. The "About" panel was just an example.
The standard About panel isn't in your nib; it's generated within the framework.
You can change the text of the panel by writing a Credits.rtf or Credits.html file and including that in your app bundle. (You may already have Credits.rtf supplied by the project template. If so, you should just edit that.)
If you want to make more radical changes, you'll need to create your own panel and change your About menu item to show it instead.
As far as a general procedure...no, there's no single procedure that would let you customize any standard panel in the same way. They all have their own mechanisms (e.g. some can display more panes when plug-in components are installed; some provide APIs to hide or show certain parts; some, like the About box, use bundle filename conventions to decide what to do).
For the Help panel specifically...you can't change anything about it except the web page (i.e. the help content). The toolbar, etc. is all handled by Apple. I suggest looking at this documentation for more, which also links to other important documents:
https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/OnlineHelp/Concepts/ComprehenHelp.html%23//apple_ref/doc/uid/20000017-BBCCFHAC

Objective-C: get menu information from external application

I'm trying to write a Mac OS menu extra application that displays a contextual menu containing the currently active application's menu bar items, when the user presses some hotkey. The displaying of the contextual menu I can do fine, but I can't seem to get the currently active application's menu bar items. At the moment I'm using [[[NSWorkspace sharedWorkspace] runningApplications] filteredArrayUsingPredicate:] to get the active applications' name, but NSRunningApplication seems to contain precious little other information. Is there any way I can get information about application menus from an external application?
UPDATE:
Using the ScriptingBridge framework seems to work fairly well, if you're happy using AppleScript:
SystemEventsApplication* sevApp = [SBApplication applicationWithBundleIdentifier:#"com.apple.systemevents"];
SystemEventsProcess* proc = [[sevApp applicationProcesses] objectWithName:appName];
for (SystemEventsMenuBar* menuBar in proc.menuBars) {
for (SystemEventsMenuBarItem* menuBaritem in menuBar.menuBarItems) {
NSLog(#"%#", menuBaritem.name);
}
}
will print out a list of menus available from the application's menu bar. Haven't found a way to get the contextual menu, so I won't call this answered just yet...
This was useful too: https://robnapier.net/scripting-bridge
You can use AppleScript to simulate clicking a menu item like shown here, but I'm not sure if it's possible to dynamically grab the names of all the menu items, to use that method you need to already have the names hardcoded into the app.

Making a button do the cmd + h command

Hey, I was wondering if it's possible to make a button do the cmd + h command?
This is how I was thinking.
The app will get the information as the force quit does (Apple Logo > Force Quit)
The user selected the app the user would like to hide and instead of having a force quit button I was thinking about having a hide button that does the cmd + h.
Would this be possible?
Do you mean hide the application you are running in, or hide a different application on the system? To hide the application you are in, attach the button to either the application's or first responder's hide: method. If you want to hide a different application, you have to send a hide apple event to the application.