Re: macOS, is my app active?

2019-11-25 Thread scott--- via use-livecode
It does work nicely from the IDE but as Trevor noted, the downside to using 
AppleScript in this case is that under newer version of OSX your compiled app 
will trigger a (one time) dialog asking to grant access to control “System 
Events.app”
—
Scott Morrow

> On Nov 25, 2019, at 8:46 AM, Bob Sneidar via use-livecode 
>  wrote:
> 
> on mouseUp
>   put "tell application " & quote & "System Events" & quote & cr after 
> tApplescript
>   put "set activeApp to name of first application process whose frontmost is 
> true" & cr after tApplescript
>   put "return activeApp" & cr after tApplescript
>   put "end tell" & cr after tApplescript
>   do tAppleScript as appleScript
>   put the result
> end mouseUp
> 
> works for me
> 
> Bob S
> 
> 
>> On Nov 23, 2019, at 06:11 , Klaus major-k via use-livecode 
>>  wrote:
>> 
>> Hi Trevor,
>> 
>>> Am 23.11.2019 um 15:06 schrieb Trevor DeVore via use-livecode 
>>> :
>>> 
>>> On Sat, Nov 23, 2019 at 6:24 AM Klaus major-k via use-livecode <
>>> use-livecode@lists.runrev.com> wrote:
>>> 
 Hi friends,
 
 can we check if our standalone is currently active, means in
 the "foreground" or if it is not active? Know what I mean?
 If yes, how can we do that? LC? AppleScript?
 
 I want to alert the user if the app is active, but not if the app
 is not active.
>>> Apple provides API calls to do this and wrapping Objective-C APIs is pretty
>>> straightforward. The APIs you are interested in:
>>> ...
>>> Regarding step 6 - If you don't want to store your extension externally to
>>> your application you can also use the "+" button in the EB to install the
>>> extension in your LC environment. Now the extension will load whenever you
>>> launch LC and you can select "NSWorkspace" in the Standalone Builder
>>> Inclusions tab so that the extension is bundled with your executable.
>>> 
>>> -- 
>>> Trevor DeVore
>> 
>> wow, lots of infos, thank you very much, but maybe a little overkill for me.
>> 
>> It would suffice for me to get this little snippet to work:
>> -
>> tell application "System Events"
>>  set activeApp to name of first application process whose frontmost is 
>> true
>>  return activeApp
>> end tell
>> 
>> Works fine in the AppleScript Editor, but I get "execution error" when DOing 
>> this in LC!?
>> Any hints appreciated!
>> 
>> Thanks a lot!
>> 
>> 
>> Best
>> 
>> Klaus
>> --
>> Klaus Major
>> https://www.major-k.de
>> kl...@major-k.de
>> 
>> 
>> ___
>> use-livecode mailing list
>> use-livecode@lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription 
>> preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
> 
> 
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: macOS, is my app active?

2019-11-25 Thread Bob Sneidar via use-livecode
on mouseUp
   put "tell application " & quote & "System Events" & quote & cr after 
tApplescript
   put "set activeApp to name of first application process whose frontmost is 
true" & cr after tApplescript
   put "return activeApp" & cr after tApplescript
   put "end tell" & cr after tApplescript
   do tAppleScript as appleScript
   put the result
end mouseUp

works for me

Bob S


> On Nov 23, 2019, at 06:11 , Klaus major-k via use-livecode 
>  wrote:
> 
> Hi Trevor,
> 
>> Am 23.11.2019 um 15:06 schrieb Trevor DeVore via use-livecode 
>> :
>> 
>> On Sat, Nov 23, 2019 at 6:24 AM Klaus major-k via use-livecode <
>> use-livecode@lists.runrev.com> wrote:
>> 
>>> Hi friends,
>>> 
>>> can we check if our standalone is currently active, means in
>>> the "foreground" or if it is not active? Know what I mean?
>>> If yes, how can we do that? LC? AppleScript?
>>> 
>>> I want to alert the user if the app is active, but not if the app
>>> is not active.
>> Apple provides API calls to do this and wrapping Objective-C APIs is pretty
>> straightforward. The APIs you are interested in:
>> ...
>> Regarding step 6 - If you don't want to store your extension externally to
>> your application you can also use the "+" button in the EB to install the
>> extension in your LC environment. Now the extension will load whenever you
>> launch LC and you can select "NSWorkspace" in the Standalone Builder
>> Inclusions tab so that the extension is bundled with your executable.
>> 
>> -- 
>> Trevor DeVore
> 
> wow, lots of infos, thank you very much, but maybe a little overkill for me.
> 
> It would suffice for me to get this little snippet to work:
> -
> tell application "System Events"
>   set activeApp to name of first application process whose frontmost is 
> true
>   return activeApp
> end tell
> 
> Works fine in the AppleScript Editor, but I get "execution error" when DOing 
> this in LC!?
> Any hints appreciated!
> 
> Thanks a lot!
> 
> 
> Best
> 
> Klaus
> --
> Klaus Major
> https://www.major-k.de
> kl...@major-k.de
> 
> 
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: macOS, is my app active?

2019-11-24 Thread Klaus major-k via use-livecode
Hi all,

no matter what I tried with AppleScript, all I got was -> execution error

So I took the time and tested Trevors solution and thanks to the idiot-proof
instructions, this was a snap even for a LCB ignorant like moi! :-)
Thanks again Trevor!

And thanks to all for your suggestions!


Best

Klaus
--
Klaus Major
https://www.major-k.de
kl...@major-k.de


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: macOS, is my app active?

2019-11-23 Thread Ken Ray via use-livecode
Klaus,

I have a function that generally works with this AppleScript:

function stsGetFrontmostProcess
  put "tell app `System Events`" & cr & \
  "get (the name of every application process whose frontmost is true) 
as string" & cr & \
  "end tell" into tScript
  replace "`" with quote in tScript
  do tScript as AppleScript
  put the result into tResult
  replace quote with "" in tResult
  return tResult
end stsGetFrontmostProcess

Give that a try and see if it works for you.

Ken

> On Nov 23, 2019, at 6:24 AM, Klaus major-k via use-livecode 
>  wrote:
> 
> Hi friends,
> 
> can we check if our standalone is currently active, means in
> the "foreground" or if it is not active? Know what I mean?
> If yes, how can we do that? LC? AppleScript?
> 
> I want to alert the user if the app is active, but not if the app 
> is not active.
> 
> Thanks in advance!
> 
> 
> Best
> 
> Klaus
> --
> Klaus Major
> https://www.major-k.de
> kl...@major-k.de
> 
> 
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: macOS, is my app active?

2019-11-23 Thread JB via use-livecode
Trevor, your code is written really nice!
Thanks for the links and code.

JB

> On Nov 23, 2019, at 5:24 PM, Trevor DeVore via use-livecode 
>  wrote:
> 
> On Sat, Nov 23, 2019 at 7:09 PM scott--- via use-livecode <
> use-livecode@lists.runrev.com> wrote:
> 
>> Trevor,
>> 
>> Those directions were awesome! I saw the security warning with the
>> AppleScript method. Your extension method avoided it. Thank you.
> 
> 
> You’re welcome Scott.
> 
> -- 
> Trevor DeVore
> ScreenSteps
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: macOS, is my app active?

2019-11-23 Thread Trevor DeVore via use-livecode
On Sat, Nov 23, 2019 at 7:09 PM scott--- via use-livecode <
use-livecode@lists.runrev.com> wrote:

> Trevor,
>
> Those directions were awesome! I saw the security warning with the
> AppleScript method. Your extension method avoided it. Thank you.


You’re welcome Scott.

-- 
Trevor DeVore
ScreenSteps
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: macOS, is my app active?

2019-11-23 Thread scott--- via use-livecode
Trevor, 

Those directions were awesome! I saw the security warning with the AppleScript 
method. Your extension method avoided it. Thank you.

—
Scott Morrow

Elementary Software
(Now with 20% less chalk dust!)
web   https://elementarysoftware.com/
email sc...@elementarysoftware.com
booth1-800-615-0867
--

> On Nov 23, 2019, at 6:06 AM, Trevor DeVore via use-livecode 
>  wrote:
> 
> On Sat, Nov 23, 2019 at 6:24 AM Klaus major-k via use-livecode <
> use-livecode@lists.runrev.com> wrote:
> 
>> Hi friends,
>> 
>> can we check if our standalone is currently active, means in
>> the "foreground" or if it is not active? Know what I mean?
>> If yes, how can we do that? LC? AppleScript?
>> 
>> I want to alert the user if the app is active, but not if the app
>> is not active.
>> 
> 
> Apple provides API calls to do this and wrapping Objective-C APIs is pretty
> straightforward. The APIs you are interested in:
> 
> Get frontmost app:
> https://developer.apple.com/documentation/appkit/nsworkspace/1532097-frontmostapplication?language=objc
> 
> Get bundle identifier of frontmost app:
> https://developer.apple.com/documentation/appkit/nsrunningapplication/1529140-bundleidentifier?language=objc
> 
> I have a macOS LCB "playground" repo where I test a number of things out
> and upload them for others to see. Take a look at
> the NSWorkspaceGetFrontmostApplication function:
> 
> https://github.com/trevordevore/lc-macos-toolset/blob/master/NSWorkspace/nsworkspace.lcb#L133
> 
> You can call it like this:
> 
> ```
> put NSWorkspaceGetFrontmostApplication("bundle id")
> ```
> 
> If I run the function from within LiveCode it returns "com.runrev.livecode".
> 
> If I run the following in the message box and switch to Chrome it returns
> "com.google.Chrome":
> 
> ```
> wait 1 second;put NSWorkspaceGetFrontmostApplication("bundle id")
> ```
> 
> So I would think it would do what you want. You would, however, need to
> compile the nsworkspace.lcb and load the resulting extension in your app.
> Here are some quick instructions in case you want to try:
> 
> 1. Download and unzip repo using "Clone or Download" link found at
> https://github.com/trevordevore/lc-macos-toolset
> 2. Launch LC 9 and open the Extension Builder (EB) from Tools > Extension
> Builder menu.
> 3. Click on the folder icon in top right of EB window and select the
> ./NSWorkspace/nsworkspace.lcb file.
> 4. Click on play button in bottom left of EB window.
> 5. Test `wait 1 second;put NSWorkspaceGetFrontmostApplication("bundle id")`
> in the message box. It should return a value.
> 6. Look in the ./NSWorkspace folder for the module.2.lcm file. This is the
> file that can be renamed, added to your application folder, and loaded
> using `load extension`.
> 
> Regarding step 6 - If you don't want to store your extension externally to
> your application you can also use the "+" button in the EB to install the
> extension in your LC environment. Now the extension will load whenever you
> launch LC and you can select "NSWorkspace" in the Standalone Builder
> Inclusions tab so that the extension is bundled with your executable.
> 
> -- 
> Trevor DeVore
> ScreenSteps
> www.screensteps.com
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: macOS, is my app active?

2019-11-23 Thread hh via use-livecode
> Klaus M. wrote:
> Still -> execution error

It works here in the IDE on MacOS 10.14.6 and 10.15.1 using LC 9.5.0. or LC 
8.1.10. (I stopped using unstable LC versions a while ago).
Did you try from the IDE?

If it is from the standalone only you could also try to use osascript
via shell:

get shell("osascript " & )
or use "osascript -e " for direct input.

Works all here...


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: macOS, is my app active?

2019-11-23 Thread JB via use-livecode
That is what I did too!

Then I went to each line and deleted the
white space until I ended up on the line
above, after that I pressed return so the
text went to its own line and it reformatted
that line properly.  This process should be
done for each line.

JB

> On Nov 23, 2019, at 3:42 PM, Klaus major-k via use-livecode 
>  wrote:
> 
> Hi JB,
> 
>> Am 24.11.2019 um 00:27 schrieb JB via use-livecode 
>> :
>> 
>> Hi Klaus,
>> 
>> I did that and got a error but by reformatting
>> the code properly it worked.
> 
> what do you mean by "reformatting"?
> I copied this from a TXT file and "pasted unformatted" into my field.
> 
> Still -> execution error
> 
> I suspect this is a permission thing, maybe I need to grant LC, and my later 
> app,
> permissions in the macOS Settings panel.
> 
> So the, little more complex, solution Trevor proposed suddenly looks a lot 
> more appealing! :-D
> 
>> JB
>> ...
>>> 
 This is fld "IN" (your snippet):
 
 tell application "System Events"
 set activeApp to name of first application process whose frontmost is true
 return activeApp
 end tell
 
 on mouseUp
 do fld "IN" as "applescript"
 put the result into fld "OUT"
 end mouseUp
 
 yields in fld "OUT":
 "Livecode-Community" or
 "LiveCode-Indy" or
 "LiveCode-Business"
> 
> Best
> 
> Klaus
> 
> --
> Klaus Major
> https://www.major-k.de
> kl...@major-k.de
> 
> 
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
> 


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: macOS, is my app active?

2019-11-23 Thread Klaus major-k via use-livecode
Hi JB,

> Am 24.11.2019 um 00:27 schrieb JB via use-livecode 
> :
> 
> Hi Klaus,
> 
> I did that and got a error but by reformatting
> the code properly it worked.

what do you mean by "reformatting"?
I copied this from a TXT file and "pasted unformatted" into my field.

Still -> execution error

I suspect this is a permission thing, maybe I need to grant LC, and my later 
app,
permissions in the macOS Settings panel.

So the, little more complex, solution Trevor proposed suddenly looks a lot more 
appealing! :-D

> JB
> ...
>> 
>>> This is fld "IN" (your snippet):
>>> 
>>> tell application "System Events"
>>> set activeApp to name of first application process whose frontmost is true
>>> return activeApp
>>> end tell
>>> 
>>> on mouseUp
>>> do fld "IN" as "applescript"
>>> put the result into fld "OUT"
>>> end mouseUp
>>> 
>>> yields in fld "OUT":
>>> "Livecode-Community" or
>>> "LiveCode-Indy" or
>>> "LiveCode-Business"

Best

Klaus

--
Klaus Major
https://www.major-k.de
kl...@major-k.de


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: macOS, is my app active?

2019-11-23 Thread JB via use-livecode
Hi Klaus,

I did that and got a error but by reformatting
the code properly it worked.

JB

> On Nov 23, 2019, at 1:04 PM, Klaus major-k via use-livecode 
>  wrote:
> 
> Hallo Hermann,
> 
>> Am 23.11.2019 um 17:16 schrieb hh via use-livecode 
>> :
>> 
>> MacOS 10.15.1
> 
> macOS 10.14.6 here, LC 9.5.1 rc1
> 
>> This is fld "IN" (your snippet):
>> 
>> tell application "System Events"
>> set activeApp to name of first application process whose frontmost is true
>> return activeApp
>> end tell
>> 
>> on mouseUp
>> do fld "IN" as "applescript"
>> put the result into fld "OUT"
>> end mouseUp
>> 
>> yields in fld "OUT":
>> "Livecode-Community" or
>> "LiveCode-Indy" or
>> "LiveCode-Business"
> 
> no, it doesn't unfortunately!
> 
> I wrote (this is in fact in my field 1):
>> -
>> tell application "System Events"
>>  set activeApp to name of first application process whose frontmost is 
>> true
>>  return activeApp
>> end tell
>> 
>> Works fine in the AppleScript Editor, but I get "execution error" when DOing 
>> this in LC!?
> 
> With DOing I meant of course your above mentioned procedere "on mouseup":
> 
> on mouseUp
>  do fld 1 as AppleScript
>  put the result into fld 2
> end mouseUp
> 
> But all I get in field 2 is -> execution error
> Clueless...
> 
> 
> Best
> 
> Klaus
> 
> --
> Klaus Major
> https://www.major-k.de
> kl...@major-k.de
> 
> 
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
> 


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: macOS, is my app active?

2019-11-23 Thread Klaus major-k via use-livecode
Hi Trevor,

> Am 23.11.2019 um 17:27 schrieb Trevor DeVore via use-livecode 
> :
> On Sat, Nov 23, 2019 at 8:11 AM Klaus major-k via use-livecode <
> use-livecode@lists.runrev.com> wrote:
>> wow, lots of infos, thank you very much, but maybe a little overkill for
>> me.
>> 
>> It would suffice for me to get this little snippet to work:
>> -
>> tell application "System Events"
>>set activeApp to name of first application process whose frontmost
>> is true
>>return activeApp
>> end tell
>> 
>> Works fine in the AppleScript Editor, but I get "execution error" when
>> DOing this in LC!?
>> Any hints appreciated!
>> 
>> Thanks a lot!
> You’re welcome. I don’t know the solution to your problem with AppleScript.
> If you do go the AppleScript route just check that you don’t trigger any
> security warnings in later versions of macOS. Maybe that isn’t a big deal
> for your app but it is worth checking.

I already stored your mail for future use and will surely take a deeper look
once I have my current project up and running!

> Trevor DeVore

Best

Klaus

--
Klaus Major
https://www.major-k.de
kl...@major-k.de


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: macOS, is my app active?

2019-11-23 Thread Klaus major-k via use-livecode
Hallo Hermann,

> Am 23.11.2019 um 17:16 schrieb hh via use-livecode 
> :
> 
> MacOS 10.15.1

macOS 10.14.6 here, LC 9.5.1 rc1

> This is fld "IN" (your snippet):
> 
> tell application "System Events"
>  set activeApp to name of first application process whose frontmost is true
>  return activeApp
> end tell
> 
> on mouseUp
>  do fld "IN" as "applescript"
>  put the result into fld "OUT"
> end mouseUp
> 
> yields in fld "OUT":
> "Livecode-Community" or
> "LiveCode-Indy" or
> "LiveCode-Business"

no, it doesn't unfortunately!

I wrote (this is in fact in my field 1):
> -
> tell application "System Events"
>   set activeApp to name of first application process whose frontmost is 
> true
>   return activeApp
> end tell
> 
> Works fine in the AppleScript Editor, but I get "execution error" when DOing 
> this in LC!?

With DOing I meant of course your above mentioned procedere "on mouseup":

on mouseUp
  do fld 1 as AppleScript
  put the result into fld 2
end mouseUp

But all I get in field 2 is -> execution error
Clueless...


Best

Klaus

--
Klaus Major
https://www.major-k.de
kl...@major-k.de


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: macOS, is my app active?

2019-11-23 Thread Trevor DeVore via use-livecode
On Sat, Nov 23, 2019 at 8:11 AM Klaus major-k via use-livecode <
use-livecode@lists.runrev.com> wrote:

>
> wow, lots of infos, thank you very much, but maybe a little overkill for
> me.
>
> It would suffice for me to get this little snippet to work:
> -
> tell application "System Events"
> set activeApp to name of first application process whose frontmost
> is true
> return activeApp
> end tell
> 
> Works fine in the AppleScript Editor, but I get "execution error" when
> DOing this in LC!?
> Any hints appreciated!
>
> Thanks a lot!


You’re welcome. I don’t know the solution to your problem with AppleScript.
If you do go the AppleScript route just check that you don’t trigger any
security warnings in later versions of macOS. Maybe that isn’t a big deal
for your app but it is worth checking.

- -
Trevor DeVore

>
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: macOS, is my app active?

2019-11-23 Thread hh via use-livecode


MacOS 10.15.1

This is fld "IN" (your snippet):

tell application "System Events"
  set activeApp to name of first application process whose frontmost is true
  return activeApp
end tell

on mouseUp
  do fld "IN" as "applescript"
  put the result into fld "OUT"
end mouseUp

yields in fld "OUT":

"Livecode-Community" or
"LiveCode-Indy" or
"LiveCode-Business"

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: macOS, is my app active?

2019-11-23 Thread Klaus major-k via use-livecode
Hi Trevor,

> Am 23.11.2019 um 15:06 schrieb Trevor DeVore via use-livecode 
> :
> 
> On Sat, Nov 23, 2019 at 6:24 AM Klaus major-k via use-livecode <
> use-livecode@lists.runrev.com> wrote:
> 
>> Hi friends,
>> 
>> can we check if our standalone is currently active, means in
>> the "foreground" or if it is not active? Know what I mean?
>> If yes, how can we do that? LC? AppleScript?
>> 
>> I want to alert the user if the app is active, but not if the app
>> is not active.
> Apple provides API calls to do this and wrapping Objective-C APIs is pretty
> straightforward. The APIs you are interested in:
> ...
> Regarding step 6 - If you don't want to store your extension externally to
> your application you can also use the "+" button in the EB to install the
> extension in your LC environment. Now the extension will load whenever you
> launch LC and you can select "NSWorkspace" in the Standalone Builder
> Inclusions tab so that the extension is bundled with your executable.
> 
> -- 
> Trevor DeVore

wow, lots of infos, thank you very much, but maybe a little overkill for me.

It would suffice for me to get this little snippet to work:
-
tell application "System Events"
set activeApp to name of first application process whose frontmost is 
true
return activeApp
end tell

Works fine in the AppleScript Editor, but I get "execution error" when DOing 
this in LC!?
Any hints appreciated!

Thanks a lot!


Best

Klaus
--
Klaus Major
https://www.major-k.de
kl...@major-k.de


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: macOS, is my app active?

2019-11-23 Thread Trevor DeVore via use-livecode
On Sat, Nov 23, 2019 at 6:24 AM Klaus major-k via use-livecode <
use-livecode@lists.runrev.com> wrote:

> Hi friends,
>
> can we check if our standalone is currently active, means in
> the "foreground" or if it is not active? Know what I mean?
> If yes, how can we do that? LC? AppleScript?
>
> I want to alert the user if the app is active, but not if the app
> is not active.
>

Apple provides API calls to do this and wrapping Objective-C APIs is pretty
straightforward. The APIs you are interested in:

Get frontmost app:
https://developer.apple.com/documentation/appkit/nsworkspace/1532097-frontmostapplication?language=objc

Get bundle identifier of frontmost app:
https://developer.apple.com/documentation/appkit/nsrunningapplication/1529140-bundleidentifier?language=objc

I have a macOS LCB "playground" repo where I test a number of things out
and upload them for others to see. Take a look at
the NSWorkspaceGetFrontmostApplication function:

https://github.com/trevordevore/lc-macos-toolset/blob/master/NSWorkspace/nsworkspace.lcb#L133

You can call it like this:

```
put NSWorkspaceGetFrontmostApplication("bundle id")
```

If I run the function from within LiveCode it returns "com.runrev.livecode".

If I run the following in the message box and switch to Chrome it returns
"com.google.Chrome":

```
wait 1 second;put NSWorkspaceGetFrontmostApplication("bundle id")
```

So I would think it would do what you want. You would, however, need to
compile the nsworkspace.lcb and load the resulting extension in your app.
Here are some quick instructions in case you want to try:

1. Download and unzip repo using "Clone or Download" link found at
https://github.com/trevordevore/lc-macos-toolset
2. Launch LC 9 and open the Extension Builder (EB) from Tools > Extension
Builder menu.
3. Click on the folder icon in top right of EB window and select the
./NSWorkspace/nsworkspace.lcb file.
4. Click on play button in bottom left of EB window.
5. Test `wait 1 second;put NSWorkspaceGetFrontmostApplication("bundle id")`
in the message box. It should return a value.
6. Look in the ./NSWorkspace folder for the module.2.lcm file. This is the
file that can be renamed, added to your application folder, and loaded
using `load extension`.

Regarding step 6 - If you don't want to store your extension externally to
your application you can also use the "+" button in the EB to install the
extension in your LC environment. Now the extension will load whenever you
launch LC and you can select "NSWorkspace" in the Standalone Builder
Inclusions tab so that the extension is bundled with your executable.

-- 
Trevor DeVore
ScreenSteps
www.screensteps.com
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: macOS, is my app active?

2019-11-23 Thread Klaus major-k via use-livecode
Hi all,

> Am 23.11.2019 um 13:24 schrieb Klaus major-k via use-livecode 
> :
> 
> Hi friends,
> 
> can we check if our standalone is currently active, means in
> the "foreground" or if it is not active? Know what I mean?
> If yes, how can we do that? LC? AppleScript?
> 
> I want to alert the user if the app is active, but not if the app 
> is not active.

I found this snippet on the net:

tell application "System Events"
set activeApp to name of first application process whose frontmost is 
true
return activeApp
end tell
--

Works fine in the AppleScript Editor, but I get "execution error" when DOing 
this in LC!?
Any hints appreciated!


Best

Klaus

--
Klaus Major
https://www.major-k.de
kl...@major-k.de


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


macOS, is my app active?

2019-11-23 Thread Klaus major-k via use-livecode
Hi friends,

can we check if our standalone is currently active, means in
the "foreground" or if it is not active? Know what I mean?
If yes, how can we do that? LC? AppleScript?

I want to alert the user if the app is active, but not if the app 
is not active.

Thanks in advance!


Best

Klaus
--
Klaus Major
https://www.major-k.de
kl...@major-k.de


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode