Jump to content

Recommended Posts

Try:

on recurseMenu(menustuff)
	tell application "System Events"
		return menus of menustuff
	end tell
end recurseMenu

 

Also have a look at this code snippet from GitHub/FreeKalter

 

I dont' know why its written that way with a fixed depth, but the comment says "This script uses UI element scripting to return a list of every menuitem of every menu for every application currently running."

Edited by Benzi

Share this post


Link to post

Also if you have

on recurseMenu(menustuff)
	tell application "System Events"
		set menuItems to {}
		repeat with menu_level1 in every menu of menustuff
			set level2menus to (name of every menu item of menu_level1 whose name is not missing value)
			set menuItems to menuItems & (name of menu_level1) & {level2menus}
		end repeat
	end tell
end recurseMenu

 

It will give you output as:

 

{  

     "Level 1 Menu A" , { "A subitem 1", "A subitem 2", "A subitem 3" } ,  

     "Level 2 Menu B",  { "B subitem 1", "B subitem 2"}

      ....and so on

}

 

Some code wrangling needed to get it truly recursive. (No idea how fast this will be too...) 

Edited by Benzi

Share this post


Link to post

Hey guys, 

I haven't looked into it but here's what happened to this workflow for me recently:

On VLC, I used to type "menu subtitles" to get to Video > Subtitles Track > Disable but it recently stopped working. Actually even "menu disable" doesn't work to get it either... It's weird because I still get Video > Subtitles Track > Open File... 

Any idea?

Share this post


Link to post

Hey guys, 

I haven't looked into it but here's what happened to this workflow for me recently:

On VLC, I used to type "menu subtitles" to get to Video > Subtitles Track > Disable but it recently stopped working. Actually even "menu disable" doesn't work to get it either... It's weird because I still get Video > Subtitles Track > Open File... 

Any idea?

 

Hi Florian,

This happens because VLC changes its menu contents based on context. When a file is not open, the Video > Subtitles Track menu is disabled. But, it has the Open File... sub menu item internally (though not accessible from the UI physically). Now if you open a video file that has subtitles that VLC can load, the Disable option gets added to Video > Subtitles Track dynamically.

 

The way the original workflow works is that it caches the contents of the menu items only once. So, if you had VLC open at the time the sub menu items were not present, the menu cache will not have those (and the menu cache is used to search for appropriate commands).

 

Since this depends entirely on the state of the application and when exactly the cache gets created, outcome will be different for different users. (I faced similar issues in Chrome, where a menu item renames from Enter Presentation Mode to Exit Presentation Mode).

 

In short, you need to tell the workflow to re-cache the menu entries. The original workflow does not have that option, but I modified it to include an option "m :refresh" to recreate the cache on demand.

 

You can either download my modified version or you can go to you /tmp folder and delete the cache manually, and then try searching for Disable when VLC has that menu item in place (when using the original version).

 

Hope this helps.

 

(PS this problem is more general, and I see this in many other apps apart from VLC and Chrome...)

Share this post


Link to post

This is one of those plugins with the power to change the way you use your mac, making you more productive in the process. I loved that in Quicksilver and i got really excited when I saw this plugin for Alfred.

 

But it's not quite usable still, even with Benzi's version the first load is really slow and caching doesn't seem to persist.

 

Do you guys think it will be possible to improve this in the future?

Share this post


Link to post

This is one of those plugins with the power to change the way you use your mac, making you more productive in the process. I loved that in Quicksilver and i got really excited when I saw this plugin for Alfred.

 

But it's not quite usable still, even with Benzi's version the first load is really slow and caching doesn't seem to persist.

 

Do you guys think it will be possible to improve this in the future?

 

Probably, but it's going to require Objective-C coding. I've played around with it, but haven't gotten as far as I need to. 

Share this post


Link to post

This is one of those plugins with the power to change the way you use your mac, making you more productive in the process. I loved that in Quicksilver and i got really excited when I saw this plugin for Alfred.

 

But it's not quite usable still, even with Benzi's version the first load is really slow and caching doesn't seem to persist.

 

Do you guys think it will be possible to improve this in the future?

Yes, Objective-C can search the menu bar is much faster than AppleScript. Quicksilver's menu bar search plugin does this; unfortunately, it is tied to Quicksilver's feedback architecture. I've been tinkering with the Quicksilver plugin's source code, but I haven't quite wrapped my head around Objective-C :(

Share this post


Link to post

Hey guys,

I know that it feels nice to do everything possible right inside Alfred, but sometimes you have much better way.

In your case you should just add a shortcut to the "Show Help Menu" action, you will then just have to type what you want and hit enter.

Much faster and reliable than any AppleScript plugin.

What it looks like : http://dl.dropbox.com/u/574568/Screenshots/y5Q3.png

Share this post


Link to post

Hey guys,

I know that it feels nice to do everything possible right inside Alfred, but sometimes you have much better way.

In your case you should just add a shortcut to the "Show Help Menu" action, you will then just have to type what you want and hit enter.

Much faster and reliable than any AppleScript plugin.

What it looks like : http://dl.dropbox.com/u/574568/Screenshots/y5Q3.png

 

From my experience, the Help menu doesn't "learn" which menu items you use the most, unlike Alfred. Just another reason I'd like to see this done in Alfred.

Edited by Clinton Strong

Share this post


Link to post

That's a good point also:

 

From my experience, the Help menu doesn't "learn" which menu items you use the most, unlike Alfred. Just another reason I'd like to see this done in Alfred.

Share this post


Link to post

Benzi, sorry to badger, but is there a way for me to modify this to *only* show options from the Services menu? I think that this could potentially be quite useful to people (and it's one of the Launchbar features that Alfred lacks).

 

No worries if you're too busy, but if you point me in the right direction I can *try* to make this work myself.

Share this post


Link to post

Benzi, sorry to badger, but is there a way for me to modify this to *only* show options from the Services menu? I think that this could potentially be quite useful to people (and it's one of the Launchbar features that Alfred lacks).

 

No worries if you're too busy, but if you point me in the right direction I can *try* to make this work myself.

 

Hi, something to start with: from what I could figure out, enumerate.scpt generates the menu content list which the Ruby script then parses out and generates a menu structure. If you modify enumerate.scpt to just output the menu contents of the Services menu, it should technically work...

 

 

 

Below is a modified version that just outputs the Services menu (not very strong with AppleScript, there might be a better way to do this....)

 

 


 

on run argv
    tell application "System Events"
        set _app to item 1 of (every process whose frontmost is true)
        set _app_name to name of _app
        tell _app
            set menuExists to menu bar 1 exists
            if (menuExists) then tell menu bar 1
                set _services_item to item 1 of (every menu item of (item 1 of (every menu of item 1 of (item 2 of (every menu bar item)))) whose title is "Services")
                set _services_stuff to entire contents of _services_item
                try
                    || of _services_stuff -- Deliberate error.
                on error stuff -- Get the error message
                end try
                
                return stuff
            end tell
        end tell
    end tell
end run
 
Edited by Benzi

Share this post


Link to post
Guest urtlnomis

Hi guys, I have a bit of experience with AppleScript and I wanna help. First question, do we have a proper github repo? Seem like everybody is just posting stuff from their dropbox. @ctwise and @Benzi (I guess..)?

Share this post


Link to post

Hi guys, I have a bit of experience with AppleScript and I wanna help. First question, do we have a proper github repo? Seem like everybody is just posting stuff from their dropbox. @ctwise and @Benzi (I guess..)?

 

Check out @ctwise's enhanced version that uses ObjC to get the menu contents - its much faster than this version. @ctwise's GitHub repo is here (whole bunch of workflows)

Share this post


Link to post
Guest urtlnomis

Nice, this is awesome, thanks so much!

Share this post


Link to post

Great workflow. 

 

Is it possible to make it suggest keyboard shortcut for found command? 

 

For example I'm typing

 

m new tab in chrome:

Fullscreen-21-01-2014-14-27.png

 

And it suggests in brackets that shortcut for it is "⌘T"

 

It would be great:)

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...