• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
3

SDK: Plugin dependent on application running

Participant ,
Nov 21, 2023 Nov 21, 2023

Copy link to clipboard

Copied

Is it possible for a plugin (or scripts within a plugin) to work only if a particular application is running on the user's system? This would be macOS-specific.

 

If not, I could probably use LrFileUtils.exists( path ) to determine if an application exists but this wouldn't tell me if the application is running, just if it exists. 

 

Any tips would be greatly appreciated.

 

[Mod: Title edited to show it's SDK related]

TOPICS
macOS , SDK

Views

165

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 21, 2023 Nov 21, 2023

Copy link to clipboard

Copied

You could run the this command line using LrTasks.execute() to examine the list of running processes for the one you're interested in:

 

ps xo command > temp-file

 

I think you could also run an Applescript script that queries System Events for a process. But every time I turn to Applescript, there goes several hours of googling for all of its peculiarities.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 21, 2023 Nov 21, 2023

Copy link to clipboard

Copied

Thanks, @johnrellis - sort of related question, is it possible to have a plugin's menu items show only when certain conditions are met? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 21, 2023 Nov 21, 2023

Copy link to clipboard

Copied

"is it possible to have a plugin's menu items show only when certain conditions are met?"

 

Not in general. You can specify some conditions on selected photos (e.g. whether a photo is selected), as described in the SDK Programmer's Guide, but that's it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 21, 2023 Nov 21, 2023

Copy link to clipboard

Copied

That was my initial understanding as well. Thanks again for the confirmation.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 22, 2023 Nov 22, 2023

Copy link to clipboard

Copied

@johnrellis I was able to create an Applescript that can identify if my particular application is running. I am trying to use it within the context of the LrTasks.execute() but I am not exactly sure how it should be formatted. 

 

My current method is to take the script that is working in Script Editor and paste that in between the () in LrTasks.execute() as shown below.

 

local running = LrTasks.execute(tell application "System Events"
set ids to bundle identifier of every application process
if ids contains "nameofbundleid" then
return "Running"
else
return "Not running"
end if
end tell)

This results in the error: ')' expected near 'application'

 

Is it possible that Applescript cannot be used within LrTasks.execute() or do you have any other thoughts?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 22, 2023 Nov 22, 2023

Copy link to clipboard

Copied

[This post contains formatting and embedded images that don't appear in email. View the post in your Web browser.]

 

LrTasks.execute() can only execute shell command lines, what you'd type at the command line in the Terminal app. You can't type Applescript directly into the command line -- you have to use the "osascript" command.  Further, LrTasks.execute() doesn't catch the output of the commands its execute -- you have to use shell redirection to capture the output into a temp file and then read the temp file.

 

So put the Applescript into a file "command-is-running.scpt". Then do something like this:

 

local exitCode = LrTasks.execute ("osascript 'path-to-scpt' > 'path-to-temp-file'")

local output = LrFileUtils.readFile ('path-to-temp-file')

 

where path-to-scpt is the fully qualified path to the file "command-is-running.scpt", and path-to-temp-file is the fully qualified path to the file where you want to capture the output of running the .scpt file.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 22, 2023 Nov 22, 2023

Copy link to clipboard

Copied

LATEST

Thanks @johnrellis! The more I dug into it the more it became apparent that Applescript is not able to be used within LrTasks.execute(), I appreciate the confirmation on your end. Thanks for the detailed instructions. Really appreciate you pointing out the fact that LrTasks.execute() doesn't catch the output. Not knowing this would have certainly presented issues on my end. Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines