简体   繁体   中英

Is it possible to invoke OS X services programmatically?

I'm trying to create new task in Appigo Todo for Mac from Alfred here. Since it provide OS X service in the service menu to let me highlight any text and create a new task from that. Is it possible to send a text to this service programmatically? (Shell script, AppleScripts, Automator, etc.)

Invoking a Service Programmatically

Though the user typically invokes a standard service by choosing an item in the Services menu, you can invoke it in code using this function:

BOOL NSPerformService(NSString *serviceItem, NSPasteboard *pboard)

This function returns YES if the service is successfully performed; otherwise, it returns NO . The name of a Services menu item (in any language) is contained in serviceItem. It must be the full name of the service; for example, “Search in Google.” The parameter pboard contains the data to be used for the service, and, when the function returns, it contains the data returned from the service. You can then do with the data what you wish.

There are a number of ways to handle this.

Here's an example of a shell command that will send a keystroke to the frontmost app via applescript:

osascript -e "tell application \"System Events\" to keystroke \"a\""

Also have a look at Cliclick , xdotool (from MacPorts) and pymaCursor .

You might also want to consider a UI automator like Sikuli

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM