views:

23

answers:

1

I was trying to replicate "take a screenshot shortcut" (cmd+shift+3) via cocoa and scripting bridge

SystemEventsApplication * sysEvent = [SBApplication applicationWithBundleIdentifier:@"com.apple.systemevents"];
[sysEvent keyCode:20 using:SystemEventsEMdsCommandDown];

but i can't send more than one SystemEventsEMds to the method.
In applescript is as easy as

key code 20 using {command down, shift down}
A: 

I kinda solved this. I was trying to get a cmd+shift+3 that serves, as all of you know, to take a screenshot. shift+3 is in the italian keyboard = to "£" so

[sysEvent keystroke:@"£" using:SystemEventsEMdsCommandDown];

does the trick I'm still wondering how would i have done with a cmd+opt+something and how to manage localization...

G3z
That won't generalize to other keyboard layouts. In the US and Dvorak keyboard layouts, £ is *option*-3, so that would in fact be ⌘⌥3, rather than ⇧⌘3. This is why you should stick to keycodes (and only simulate hotkey presses at all when there isn't an alternative such as taking the screenshot yourself).
Peter Hosey