osx service menu call to Livecode app

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
rodneyt
Posts: 128
Joined: Wed Oct 17, 2018 7:32 am

osx service menu call to Livecode app

Post by rodneyt » Wed Aug 04, 2021 1:13 pm

Hello again,

Does anyone have experience with creating a service menu item in OSX to call a livecode app? Typically these can be exposed either via a context menu or have a keyboard command (system wide) assigned to them - which when called will activate the app and pass the command in.

It seems like something that others here may have figured out, so before I research this just wanted to ask...

~ Rodney

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7214
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: osx service menu call to Livecode app

Post by jacque » Wed Aug 04, 2021 5:35 pm

I haven't used it but have you seen "macStatusMenu" in the dictionary? That seems to cover most of it.

Edit: oops, I think you mean the Services menu under the Apple menu. I don't see support for that.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: osx service menu call to Livecode app

Post by dunbarx » Wed Aug 04, 2021 6:24 pm

Jacque.

"Services Menu"?

Craig

EDIT.

Oh, under the "Finder" menu.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7214
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: osx service menu call to Livecode app

Post by jacque » Wed Aug 04, 2021 7:29 pm

Now that I'm at my Mac I see the Services menu is under the app menu in any application. It's also available in Finder when you right-click on an item.

I suspect the only way to access it from LC is to use LCB or submit an enhancement request.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

rodneyt
Posts: 128
Joined: Wed Oct 17, 2018 7:32 am

Re: osx service menu call to Livecode app

Post by rodneyt » Wed Aug 04, 2021 11:59 pm

This looks like the other option:
https://developer.apple.com/library/arc ... rvice.html

... then get it to call your app via Applescript.

kdjanz
Posts: 300
Joined: Fri Dec 09, 2011 12:12 pm
Location: Fort Saskatchewan, AB Canada

Re: osx service menu call to Livecode app

Post by kdjanz » Thu Aug 05, 2021 3:20 am

Building off the AppleScript idea, you can use Automator to create a new Quick Action that can be added to the Services menu and can also appear in the Touch Bar and Finder.

Start a new Quick Action, then in the Utilities category drag Launch Application into the workflow area on the right. A pull down will allow you to choose your compiled LiveCode app to launch. By dragging other items into the workflow, you can add documents or files for you app to work on or do post processing or other options. You then save the workflow with the name you want your users to see (perhaps the name of your app). Use the offered default folder location to save the workflow, and your new action will immediately appear in the services menu.

If you copied this Quick Action and you shipped it with your app, it could be available in an optional install folder. If the user chose to install it, all they would have to do is double click the icon. The finder then confirms that you want to install the service and automatically moves the file and icon to the hidden services folder where it needs to be - and the user will then see your app (or a shortcut to your app) in the Services folder.

Hope this helps

Kelly


Later...
just read your link and Apple has supplied better instructions than mine! No AppleScript required though.
Read before you Write! - someday I might remember that!

rodneyt
Posts: 128
Joined: Wed Oct 17, 2018 7:32 am

Re: osx service menu call to Livecode app

Post by rodneyt » Thu Aug 05, 2021 5:58 am

Thanks Kelly, very interesting.

What's the correct way to send an event from an Applescript script (e.g. a script I could run in Script Editor) to send to a Livecode compiled application?

Appreciate this may require having support for running in Development mode (when event is targeted at Livecode) and compiled (when targetting the built application)

For those interested, you can handle incoming events using an AppleEvent handler.

Incidentally it seems the Livecode dictionary doesn't seem to have an entry for this at the moment (just for the send to program entry).

Code: Select all

on appleEvent pClass, pEventID, pSender
  if pClass is "aevt" then
    request appleEvent data
    answer "Appleevent received: class"&&pClass&&"eventid:"&&pEventID &&"sender:"&&pSender &&"Data:" && it
  end if
  pass appleEvent
end appleEvent

rodneyt
Posts: 128
Joined: Wed Oct 17, 2018 7:32 am

Re: osx service menu call to Livecode app

Post by rodneyt » Thu Aug 05, 2021 6:11 am

Here's how to call a Livecode handler from an Applescript e.g. from Script editor

Code: Select all

tell application "LiveCode ..."
	activate
		do script "send \"testCallFromAS\" to stack \"mystackname\""
end tell
I'd still be interested in an example of how to send an Appleevent from script editor to Livecode, to be intercepted using the Applescript handler (see example in my previous post above)

Thread: viewtopic.php?t=633
Last edited by rodneyt on Fri Aug 06, 2021 8:53 am, edited 1 time in total.

rodneyt
Posts: 128
Joined: Wed Oct 17, 2018 7:32 am

Re: osx service menu call to Livecode app

Post by rodneyt » Fri Aug 06, 2021 6:37 am

You can use appleevents to get the name of a file dragged to your application as described here:
https://lessons.livecode.com/m/4071/l/1 ... le-onto-it

Can anyone provide an example of how to send other types of apple events to a Livecode app?

What's the best way to pass in data to a Livecode app? The method I describe above allows you to call a Livecode handler from Applescript but it doesn't seem to allow you to pass a variable in with it. Just wondering if anyone else has experimented in this area and can advise.

rodneyt
Posts: 128
Joined: Wed Oct 17, 2018 7:32 am

Re: osx service menu call to Livecode app

Post by rodneyt » Fri Aug 06, 2021 9:18 am

On the subject of Service menu. I had a go creating a system wide shortcut to activate Livecode IDE. I did this by following the instructions (see thread above) =>> open automator, creating a new service item, and choosing action to Launch then select Livecode application. Save this, it then appears under Application menu -> Services -> Launch Livecode.

You can then assign a system wide keyboard shortcut to call and activate. To assign the keyboard shortcut you go to System Preference -> Keyboard -> Shortcuts ->Services and select the shortcut you created then assign a keyboard shortut.

Keyboard shortcuts for applescript seem to have some weird-ities:
There is a weird bug where sometimes you have to go to the services menu first before the keyboard shortcuts work, apparently this issue has been around for ages and is discussed here: https://stackoverflow.com/questions/363 ... n/46060932.

So.... I am not sure how useful this is. However for anyone else running across this thread via search I include for completeness...

PaulDaMacMan
Posts: 616
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: osx service menu call to Livecode app

Post by PaulDaMacMan » Fri Aug 13, 2021 2:46 am

jacque wrote:
Wed Aug 04, 2021 7:29 pm
Now that I'm at my Mac I see the Services menu is under the app menu in any application. It's also available in Finder when you right-click on an item.

I suspect the only way to access it from LC is to use LCB or submit an enhancement request.
Yes, I'm sure this could be done with LCB FFI.
I've actually just recently come across the docs for services menu on Apple's Dev site while looking at other things (added native darkMode to my LCB macTools), but Services is not something I personally use much in my day to day work, so I probably won't be getting to that myself any time soon.

https://developer.apple.com/documentati ... guage=objc
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

PaulDaMacMan
Posts: 616
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: osx service menu call to Livecode app

Post by PaulDaMacMan » Fri Aug 13, 2021 3:00 am

Not long before Trevor DeVore created an LCB wrapper for mac Status Menu, I had worked out a bit of a hack to achieve a Status Menu of sorts, using an AppleScriptObjC applet that did bidirectional communication back and forth with my LC Stack/Standalone via AppleScript (but it had some wonky behaviors, blocking code execution waiting for user for example). I saved it somewhere. I'll try to dig out that specific code and post it here later.
Messing with that is when I discovered the bug (that's been on the "This Week In LiveCode" bug list ever since), where a standalone doesn't get an AppleScript dictionary/definition plist file included with it, which makes using LC+AppleScript in a standalone much less convenient. You can work around the problem by copying the plist from LiveCode's app bundle into the standalone or by changing the AppleScript to use Apple Events codes ( looks something like <<<exmp>>>) for certain things instead of their corresponding usual AppleScript keywords.
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

Post Reply

Return to “Talking LiveCode”