Jump to content

Recommended Posts

Hi,

 

I've created a basic workflow that searches the system's menu bar. After having used Sublime Text's command palette I wanted to have a similar system-wide functionality. EDIT: For people that haven't worked with Sublime Text's command palette: the command palette allows you to fuzzy search the entire application menu by keyboard. This saves both time on hunting down the right menu and saves you having to remember all sorts of keyboard shortcuts. For a brief introduction on Sublime Text's command palette see https://tutsplus.com/lesson/the-command-palette/

 

EDIT: Better use ctwise's "2.0" workflow http://www.alfredforum.com/topic/1993-menu-search/ [old download is still available at http://dl.dropbox.com/u/6259900/Menu%20bar%20search.alfredworkflow]

 

The current workflow does not do any fuzzy searching and every keystroke executes the entire script again. My preferred fix to this would be to have a script input that is only executed once, and have Alfred do the subsequent fuzzy matching based on the initial result.

 

Jeroen van der Neut

@jvdneut

Edited by jvdneut
Link to comment

Hi,

 

I've created a basic workflow that searches the system's menu bar. After having used Sublime Text's command palette I wanted to have a similar system-wide functionality.

 

http://dl.dropbox.com/u/6259900/Menu%20bar%20search.alfredworkflow

 

The current workflow does not do any fuzzy searching and every keystroke executes the entire script again. My preferred fix to this would be to have a script input that is only executed once, and have Alfred do the subsequent fuzzy matching based on the initial result.

 

Jeroen van der Neut

@jvdneut

 

That is awesome. I created a variant that:

 

1. Displays the menu path as the subtitle, e.g., Apple > Recent Items or Project > Recent Projects.

2. Displays the icon of the application next to the application's menu items but displays an OS/X icon next to the Apple menu items.

 

But, as discussed, this is slow for applications with many menu items so I won't be publishing the variant until I add menu caching.

Link to comment

That is awesome. I created a variant that:

 

1. Displays the menu path as the subtitle, e.g., Apple > Recent Items or Project > Recent Projects.

2. Displays the icon of the application next to the application's menu items but displays an OS/X icon next to the Apple menu items.

 

But, as discussed, this is slow for applications with many menu items so I won't be publishing the variant until I add menu caching.

 

Cool. I was hoping someone else would pick up where I left. I'm planning on making the script a bit more useful, but that will probably involve me actually having to learn AppleScript to a decent level... Did you make the changes using some more grep / sed commands or using some actual form of scripting?

 

I am a programmer by trade, but unfortunately I don't know any AppleScript, Python, Ruby or PHP, but I guess I'll have to learn in order to make this thing a little more useful. 

Link to comment

Cool. I was hoping someone else would pick up where I left. I'm planning on making the script a bit more useful, but that will probably involve me actually having to learn AppleScript to a decent level... Did you make the changes using some more grep / sed commands or using some actual form of scripting?

 

I am a programmer by trade, but unfortunately I don't know any AppleScript, Python, Ruby or PHP, but I guess I'll have to learn in order to make this thing a little more useful. 

 

Ruby. I'm no guru but I use it to hack together support scripts during development, e.g., data transformation, etc.

 

The new workflow version is here - http://tedwi.se/u/db

 
I added caching but, given the circumstances, it's very coarse. If we've never seen the app before we dump the menu contents into a file in /tmp/. Subsequent invocations, if we find the menu contents in /tmp/, we use them but kick off a background process to regenerate them. That way, we get immediate response but, by the time we get to the end of what we're typing it's current to the given app. It's pretty wasteful, but, oh well.
 
Seriously, this was a flat-out fantastic idea.
Link to comment

I'm still having issues kicking off a background update that doesn't cause Alfred to hang waiting on the initial script. I've temporarily commented out the line that does the background update. In the meantime, my use of it caused me to change how the workflow searches for menu items.

 

Instead of searching just the menu item name, it searches the whole path, e.g., 'm insert', 'm break' and 'm section' will all find 'Insert > Break > Section Break (Next Page)'. It uses case-insensitive grep, so you can do things like '^insert' to find everything belonging to the Insert top-level menu.

 

Re-download the workflow to get the latest.

Link to comment

Ted, good job on the caching. I'm currently using your workflow instead of my own :)

 

I am still exploring AppleScript to see if I can produce better results directly from it. Disabled entries should not be listed for one. Also the cache is sometimes out of date when using a toggle (Show/hide) menu option.

Link to comment

Ted, good job on the caching. I'm currently using your workflow instead of my own :)

 

I am still exploring AppleScript to see if I can produce better results directly from it. Disabled entries should not be listed for one. Also the cache is sometimes out of date when using a toggle (Show/hide) menu option.

 

I've been looking into Objective-C through the Scripting Bridge to pull down menus, both for speed and the possibility of getting shortcut keys as well to display. But my lack of knowledge of Objective-C and Cocoa are greatly hampering my efforts.

Link to comment

I've been looking into Objective-C through the Scripting Bridge to pull down menus, both for speed and the possibility of getting shortcut keys as well to display. But my lack of knowledge of Objective-C and Cocoa are greatly hampering my efforts.

 

I was actually looking into Objective-C as well now. QuickSilver (http://qsapp.com) has a similar feature for accessing menu bar items through their UI Access plugin. The source for that is on: https://github.com/quicksilver/UIAccess-qsplugin

Link to comment
  • 4 weeks later...

I've just tried this, but, isn't this the same as the actual search input inside virtually any OSX app? Actually, my Mountain Lion install (I asume everyones) comes with a shortcut (Cmd + shift + /) to toggle this

 

Pretty much, yes. I still intend to implement fuzzy searching ("wi" to match "show Web Inspector" for example), but I'm not particularly satisfied with the performance right now. I will have to figure out a way to implement caching properly first.

Link to comment

Awesome! It was one of the features i missed the most after switching from Quicksilver to Alfred. 

 

This ain't at the same level yet, but what you guys are achieving in the few days of Alfred 2 leaves no question that will get there really soon. Im loving this.

Link to comment

Hi, awesome workflow! I am using ctwise's version and its working great overall.

 

A couple of issues I noticed were to do with the workflow trying to find the application_location variable in main.rb and because of which the menu command icons for the specific application would not show up

e.g.

for Alfred Preferences, the menu commands icon were that of an empty file icon

for Google Chrome in full screen mode (Lion), the icon would not be shown. No issues in normal mode.

 

 

The following lines were added/changed in main.rb to fix most of the issues I found.

application = `osascript frontapp.scpt | sed -E 's/application process //'`.strip
application_location = `mdfind "kMDItemDisplayName=#{application}.app" | grep -i [.]app | head -n 1`.strip
if application_location.length == 0
    application_location = `mdfind "#{application}.app" | head -n 1`.strip
end
if application == "Alfred Preferences"    # overall, there should be some other way I suppose...
    application_location = "/Applications/Alfred 2.app/Contents/Preferences/Alfred Preferences.app"
end
 

 

For what its worth, hope this is useful for someone...

 

EDIT (for developers): For checking if the application and application_location variables are correctly set up, use this workflow.

Keyword is "frontmost" and it displays App name and location of the front most app... just to test things out.

Edited by Benzi
Link to comment

Hi, awesome workflow! I am using ctwise's version and its working great overall.

 

A couple of issues I noticed were to do with the workflow trying to find the application_location variable in main.rb and because of which the menu command icons for the specific application would not show up

e.g.

for Alfred Preferences, the menu commands icon were that of an empty file icon

for Google Chrome in full screen mode (Lion), the icon would not be shown. No issues in normal mode.

 

 

The following lines were added/changed in main.rb to fix most of the issues I found.


 

For what its worth, hope this is useful for someone...

 

EDIT (for developers): For checking if the application and application_location variables are correctly set up, use this workflow.

Keyword is "frontmost" and it displays App name and location of the front most app... just to test things out.

Could you maybe post the new workflow? I tried changing the file etc but after everything I just get stuck in the "Loading..." phase in Alfred and it doesn't seem to populate with anything. I tried multiple applications.

Link to comment

Could you maybe post the new workflow? I tried changing the file etc but after everything I just get stuck in the "Loading..." phase in Alfred and it doesn't seem to populate with anything. I tried multiple applications.

 

Here is my version that I am using for your reference. It is based on the version from Ted, the code for which is located in GitHub at: https://github.com/ctwise/alfred-workflows

 

NOTE:

  • Code changes to main.rb for setting application and application_location variables
  • I have included a command "m :refresh", which will refresh the menu cache of the frontmost application. Some applications have dynamic menu bar items, e.g. Chrome will populates the history menu with the URL you have visited. If you want to force a cache refresh, use this command

 

I am contributing code back to Ted via GitHub, so eventually that would be the place to look.

Link to comment

Here is my version that I am using for your reference. It is based on the version from Ted, the code for which is located in GitHub at: https://github.com/ctwise/alfred-workflows

 

NOTE:

  • Code changes to main.rb for setting application and application_location variables
  • I have included a command "m :refresh", which will refresh the menu cache of the frontmost application. Some applications have dynamic menu bar items, e.g. Chrome will populates the history menu with the URL you have visited. If you want to force a cache refresh, use this command

 

I am contributing code back to Ted via GitHub, so eventually that would be the place to look.

Hey,

I just tried this in Chrome and it doesn't seem to populate results back to Alfred.

I'm just getting stuck on this screen:

Screen%20Shot%202013-03-17%20at%2013.11.

Link to comment

Hey,

I just tried this in Chrome and it doesn't seem to populate results back to Alfred.

I'm just getting stuck on this screen:

Screen%20Shot%202013-03-17%20at%2013.11.

 

It works, it's just very slow and very stupid. It's not a very smart workflow. The bookmark entries exposed by Applescript are much larger then what's visible in the menu structure. An xml dump without typing anything is 98 megs.

Link to comment

I've been trying to get AppleScript to produce a cleaner bit of menu bar information, but keep getting stuck as I can't figure out how to recurse on these menu bar objects using AppleScript. Retrieving the properties of an object works when I ask it directly (see marker A1), but not when I use it in a "function" (see marker A2). In order to get the property at A2 I seem to have to cast the variable to a type, but that doesn't work either because the type contains a space (see marker B).

 

Maybe someone more familiar with AppleScript can tell me how to do this.

 

on run argv

    tell application "System Events"

        set _app to item 1 of (every process whose frontmost is true)

    end tell


    tell application "System Events"

        tell _app

            set menustuff to menu bar 1

 

            --(A1) retrieving property here does work

            --return menus of menustuff


            return my recurseMenu(menustuff)

        end tell

    end tell

end run

 

on recurseMenu(menustuff)

    --(B) casting doesn't work

    --set castMenuStuff to menustuff as menu bar


    --(A2) retrieving property without casting also doesn't work

    return menus of menustuff

end recurseMenu

 

In any case, what it is I'm trying to do is this: recursively walk through the menus and menu items, record their title (e.g. "New file"), path (e.g. "File-->New file"), enabled state and shortcut (e.g. Command+N).

 

When recursing it would also become simple to add a depth constraint, which will avoid cases like ctwise and The_Ben mentioned in the case of Chrome.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...