Sunday, May 9, 2021

#1 2021-04-11 03:55:12 am

NMG
Member
Registered: 2019-09-29
Posts: 54

If the app is active

I have created a Script and I have exported it as an app. I have selected "Stay open after run handler" But I want the script to run only when the app is selected (active) and stop when it is not.

Something like:
if myApp is active then
    do something
else
    stop
end if

How can I do that?

(I want to detect when myApp, is active. I mean the app that I have created with the script)

Last edited by NMG (2021-04-11 05:05:34 am)

Offline

 

#2 2021-04-11 04:58:25 am

NMG
Member
Registered: 2019-09-29
Posts: 54

Re: If the app is active

Thank you but when I say "myApp" I mean the app that I have created with the script.

Offline

 

#3 2021-04-11 05:26:30 am

NMG
Member
Registered: 2019-09-29
Posts: 54

Re: If the app is active

Ok. Great. It works.

When it is not active the app is bouncing on the doc all the time. Do you know how to avoid that?

Offline

 

#4 2021-04-11 05:26:40 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1788

Re: If the app is active

You want execute some code (-- do something) only when your stay-open app is frontmost? Like here:

Applescript:


property myAppName : "Untitled"

on idle
   tell application "System Events" to set isFrontmostApp to frontmost of process myAppName
   if isFrontmostApp then
       -- do something
       display notification "TEST dialog"
   else
       --do nothing
   end if
   return 5
end idle

Last edited by KniazidisR (2021-04-11 05:28:42 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#5 2021-04-11 05:41:17 am

NMG
Member
Registered: 2019-09-29
Posts: 54

Re: If the app is active

Yes! thank you.

Just to learn. In a previous line you use "giving up after 3"  What does it do? (it gives more than 3 dialogs)

Offline

 

#6 2021-04-11 05:46:45 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1788

Re: If the app is active

NMG wrote:

Yes! thank you.

Just to learn. In a previous line you use "giving up after 3"  What does it do? (it gives more than 3 dialogs)



It is test dialogs which gave up after 3 seconds automatically (if the user during 3 seconds doesn't press any its button, it disappears itself after 3 seconds). You should replace them with your real code. I will repeat code here for those users, who are interested:

Applescript:


property myAppName : "Untitled"

on idle
   tell application "System Events" to set isFrontmostApp to frontmost of process myAppName
   if isFrontmostApp then
       -- do something
       display dialog "TEST dialog" giving up after 3
   else
       --do nothing
   end if
   return 5
end idle

Now, I still can't understand what you want to achieve. So, I provide here code sceleton in case you want display dailogs of your stay-open app to be always on front (app is bouncing on the doc all the time when some dialog window of it is on the background, because dialod waits for response from user, but user doesn't see the dialog)

Applescript:


on idle
   activate me -- THIS
   display dialog "TEST dialog"
   return 5
end idle

Last edited by KniazidisR (2021-04-11 06:26:37 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)