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: Naive XML questions

2020-10-25 Thread Ken Ray via use-livecode
Graham, here's the basic approach (assuming your XML is in the variable 'tXML'):

put revXMLCreateTree(tXML,false,true,false) into tTreeID
put  "/gpx/trk/trkseg/trkpt[1]" into tNode  -- the brackets identify 
the instance of "trkpt" to work with
put revXMLAttribute(tTreeID, tNode,"lon") into tLonValue
put revXMLNodeContents(tTreeID,(tNode & "/ele")) into tEleValue
put tLonValue && "/" && tEleValue

>> 2.128369 / 169.623637

So to work with the third instance of "trkpt", you'd do:

put  "/gpx/trk/trkseg/trkpt[3]" into tNode

Hope this helps,

Ken


> On Oct 25, 2020, at 12:21 PM, Graham Samuel via use-livecode 
>  wrote:
> 
> I feel stupid, but even with Sarah Reichelt’s help, there are very very 
> simple things I can’t do with the LC XML functions. My current problem is 
> this:
> 
> I have a series of XML files which are in fact .gpx files - a collection of 
> GPS coordinates representing a route on the Earth’s surface. There are 
> thousands of files around which I can use as test data, so I don’t have to 
> roll my own. Taking just one of these examples, I can do the following in LC
> 
> 1. Get the user to find the file and download it
> 
> 2. Check it’s a .gpx file
> 
> 3. Turn it into an LC XML data structure with an integer ID
> 
> 4. Find out how many child nodes there are.
> 
> Then it all goes wrong, because I don’t seem to be able to address the 
> individual nodes. This is obviously needed for further progress, in functions 
> like revXMLFirstChild  and revXMLNodeContents.
> 
> I just don’t know what format to use. Sarah’s tutorial doesn’t help because 
> her data structure is too simplified.
> 
> If you’re still with me, this is what the beginning of a typical file looks 
> like:
> 
>> 
>> http://www.topografix.com/GPX/1/1; creator="Digital Crow" 
>> version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance; 
>> xsi:schemaLocation="http://www.topografix.com/GPX/1/1 
>> http://www.topografix.com/GPX/1/1/gpx.xsd;>
>> 
>> 
>>   
> 
>> 
>> 169.623637 
> 
>> 
>> 169.744722 
> 
>> 
>> 169.744722 
> 
>> 
>> 169.266626 
>> 
> etc - there may sometimes be thousands of these “trkpt” elements.
> 
> So, suppose I want to get the first instance of the “lon” attribute into a 
> local variable. How do I address the first  node etc in order to do it? 
> I have attempted various common-sense methods, but none work.
> 
> This must be child’s play to a lot of people, just not me.
> 
> Hoping for some guidance.
> 
> Graham
> ___
> 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

Ken Ray
Sons of Thunder Software, Inc.
Email: k...@sonsothunder.com
Website: https://www.sonsothunder.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: return "error" code from standalone compile

2020-12-11 Thread Ken Ray via use-livecode
Wow... I've been using Livecode since its inception (and Revolution before 
that, and even MetaCard before *that*!), and I never knew this existed!

Just goes to show that there's always something new to learn about our favorite 
development tool. 

(I wonder if anyone's put together a "list of things Livecode can do that you 
probably didn't know about" ?)

:D


Ken Ray
Sons of Thunder Software, Inc.
Email: k...@sonsothunder.com
Website: https://www.sonsothunder.com


> On Dec 10, 2020, at 11:51 AM, Douglas A. Ruisaard via use-livecode 
>  wrote:
> 
> I use AUTOHOTKEY... as a fast, dirty way to "get stuff done" when I'm either 
> too lazy or too rushed to do a "quality" job with Livecode.  It has a command 
> called "Run" & "Runwait" ... which returns the calling program's (Livecode 
> executable, in this case) return code into a predefined variable called 
> "ErrorLevel" (how original!).  So a line in a AUTOHOTKEY script for this 
> would look like:
> 
>   cmd = c:\livecode\SomeLiveCode.exe
>   RunWait, %cmd%,,UseErrorLevel
>   exitcode := ErrorLevel
>   if (exitcode > 1)
> 
> Autohotkey takes some getting used to but I think it's a handy addition to 
> development projects.. since AHK scripts can be compiled into executables, 
> themselves.
> 
> My 4.5 cents
> 
> Douglas Ruisaard
> 
>Trilogy Software
>  (250) 573-3935
> 
> 
> -Original Message-
> From: use-livecode [mailto:use-livecode-boun...@lists.runrev.com] On Behalf 
> Of John Balgenorth via use-livecode
> Sent: Thursday, December 10, 2020 4:03 AM
> To: How to use LiveCode
> Cc: John Balgenorth
> Subject: Re: return "error" code from standalone compile
> 
> Since Livecode is written in C++ here is some
> info about using return  in  C.
> 
> Every C program has a function named main.   At the
> end of the function the programmer usually writes a
> return 0;
> 
> That tells  the c  program the code has  completed
> and is exiting with  a  0 value which confirms it  has
> successfully executed the code and is quitting.
> 
> At any point above that line the programmer can  write
> a return call  but they will usually use a 1  on another
> value.  The program will exit the code at that point  and
> it does not matter what value is entered after the  return
> but 1 usually means the code failed and any other value
> but 0 means anything you want it to mean.
> 
> JB
> 
> 
>> On Dec 9, 2020, at 8:52 PM, J. Landman Gay via use-livecode 
>>  wrote:
>> 
>> I don't know much about this but it looks interesting. Is there a list of 
>> exit codes somewhere? When the OS receives the exit code, what happens? 
>> I.e., how would I use it?
>> --
>> Jacqueline Landman Gay | jac...@hyperactivesw.com
>> HyperActive Software | http://www.hyperactivesw.com
>>> On December 9, 2020 7:48:10 PM Mark Wieder via use-livecode 
>>>  wrote:
>>> 
 On 12/9/20 5:32 PM, Douglas A. Ruisaard via use-livecode wrote:
 On the completion of a stack, can the compiled executable return an error
 code like the old DOS ErrorLevel value(s)?  If so, how do you specify the
 error code?  in the on closeStack call?
>>> 
>>> See the quit command in the dictionary.
>>> 
>>> quit 42
>>> 
>>> --
>>> Mark Wieder
>>> ahsoftw...@gmail.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
> 
> ___
> 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: How to find the offset of the first character in a string that's not a tab?

2021-01-22 Thread Ken Ray via use-livecode


> On Jan 21, 2021, at 8:36 AM, Keith Clarke via use-livecode 
>  wrote:
> 
> Thanks Brian. I looked at matchChunk in the dictionary & it seems to return a 
> boolean, rather than the offset. 

The boolean is just whether or not the matchChunk operation was successful; you 
need to provide variables for the start and end character offsets in the 
function call:

if matchChunk(myString,"([^\t])",tStart,tEnd) then
  put "The offset to the first non-tab character is:" && tStart
else
  -- matchChunk had an error because the regex was bad or something
end if

I know you've moved on, but just for the record...

:D


Ken Ray
Sons of Thunder Software, Inc.
Email: k...@sonsothunder.com
Website: https://www.sonsothunder.com


> 
> Thanks all - I’ve stopped trying to find the syntax for ‘find any char but 
> this’ in offset and instead, taken Dick’s advice to iterate through the chars 
> and count the loops until char <> tab. :)
> Best,
> Keith 
> 
>> On 21 Jan 2021, at 14:03, Brian Milby via use-livecode 
>>  wrote:
>> 
>> You could also use matchChunk with a regular expression that excludes the 
>> tab character.
>> 
>> Sent from my iPhone
>> 
>>> On Jan 21, 2021, at 7:14 AM, Keith Clarke via use-livecode 
>>>  wrote:
>>> 
>>> Ah yes indeed, I’d forgotten I could test with 'put not(tab)’ in the 
>>> message box - that certainly proves the syntax was wrong! :-)
>>> Best,
>>> Keith
>>> 
> On 21 Jan 2021, at 10:49, Dick Kriesel via use-livecode 
>  wrote:
> 
> 
> 
>> On Jan 21, 2021, at 2:34 AM, Keith Clarke via use-livecode 
>>  wrote:
> 
> I was just keen to understand why offset wasn’t happy with the ‘not(tab)’ 
> in this instance.
 
 expression "not(tab)" evaluates to true, which doesn’t serve your purpose
 
 — Dick
 
 
 ___
 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
> 
> 
> ___
> 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: sort container parameters

2021-03-03 Thread Ken Ray via use-livecode
Craig,

It's because when you try to sort something, it's got to be a variable that's 
being sorted. So all of the examples you used put "toSort" into the statement 
to be "done" coming out compiled as:

sort items of "A,C,T,B" ascending

... which won't work. You need to execute:

do "sort items of toSort" && sortDir

which compiles to:

sort items of toSort ascending

... and that works.

:)


Ken Ray
Sons of Thunder Software, Inc.
Email: k...@sonsothunder.com
Website: https://www.sonsothunder.com


> On Mar 3, 2021, at 12:23 PM, Craig Newman via use-livecode 
>  wrote:
> 
> I thought I was pretty clever at using “do”, often going down several levels, 
>  evaluating the whole way before trying to execute a single  “do” statement.
> 
> Neither of the last lines seem to work:
> 
> on mouseup
> 
> put "A,C,T,B" into toSort
> 
> put "ascending" into sortDir
> 
> get "sort items of" && quote & toSort & quote && sortDir
> 
> breakpoint
> 
> --do it
> 
> --do "sort" && toSort && sortDir
> 
> do "sort" && quote & toSort & quote && sortDir
> 
> end mouseup
> 
> 
> I feel there must be a way…
> 
> Craig
> 
> 
>> On Mar 2, 2021, at 7:36 PM, Alex Tweedly via use-livecode 
>>  wrote:
>> 
>> The number of lines being sorted makes o difference.
>> 
>> The number of distinct sorts will - but at a single 'do' for each of 
>> "several hundreds", you'll not even notice except (maybe) if you are 
>> benchmarking it (around 5ms per 1000 'do's on an elderly MacBook Pro).
>> 
>> Alex.
>> 
>> On 02/03/2021 22:52, Paul Dupuis via use-livecode wrote:
>>> Okay. Thank you Ralph.
>>> 
>>> I was reluctant to use "do" for performance reasons. The sort could be 
>>> sorting a large number of lines - as many as several hundred sorts of a 
>>> thousand to ten thousand lines.
>>> 
>>> I could of course do timing trials, but does anyone from the mothership (or 
>>> anyone period) know if using "do" with a container sort causes any 
>>> appreciable performance hit? All the data is in a variable (vs fields).
>>> 
>>> 
>>> On 3/2/2021 5:19 PM, Ralph DiMola via use-livecode wrote:
 I found that you must us a "Do"(thank heaven for "Do"s) if you want to 
 make variable any LC token that colorizes like "stack", "the", "field", 
 "button", "put" or "ascending".
 
 I don't think "Do" is a kludge is this case.
 
 Ralph DiMola
 IT Director
 Evergreen Information Services
 rdim...@evergreeninfo.net
 
 -Original Message-
 From: use-livecode [mailto:use-livecode-boun...@lists.runrev.com] On 
 Behalf Of Paul Dupuis via use-livecode
 Sent: Tuesday, March 02, 2021 4:56 PM
 To: use-livecode@lists.runrev.com
 Cc: Paul Dupuis
 Subject: sort container parameters
 
 I just discovered much to my dismay that you can not execute the following:
 
 put "ascending" into tDirection
 soft lines of tContainer tDirection international
 
 apparently neither the sort direction (ascending|descending) nor the sort 
 type (international|text|datetime|numeric|binary) can be variable!
 
 That means if you want to parameterize a sort direction, you have to do 
 something like:
 
 if tDirection is "ascending" then
sort lines of tContainer ascending international else
sort lines of tCOntainer descending international end if
 
 I see this a a bug or perhaps a failure to fully robust impliment the sort 
 container command? Does any one else see this as a bug?
 
 I suppose I could work around it with a "do" but that seems like a cludge
 
 do ("sort line of tContainer" && tDirection && tSortType)
 
 Thoughts? Comments? Opinions? Am I expecting too much of LiveCode to have 
 sort direction and type actual parameters?
 
 
 ___
 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
>> 
>> ___
>> 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: lineOffset wildcard

2021-04-19 Thread Ken Ray via use-livecode
> On Apr 19, 2021, at 1:47 PM, Mark Wieder via use-livecode 
>  wrote:
> 
> On 4/19/21 11:04 AM, J. Landman Gay via use-livecode wrote:
> 
>> I don't think lineoffset supports wildcards, but you could do it with 
>> matchChunk.
> 
> Ah! matchChunk and the the number of lines of... etc...
> That should do it.

Another way to do it is to use 'filter' to get the text of the line that 
matches your wildcard, and then 'lineOffset' to find that line:

put tScript into tTemp
filter tTemp with ("local*" & tFunctionName & "*")
put lineOffset((cr & tTemp & cr),(cr & tScript & cr)) into tPos

Not sure if 'filter' is faster than 'matchChunk' when dealing with large 
scripts, but I have a feeling it might be...


Ken Ray
Sons of Thunder Software, Inc.
Email: k...@sonsothunder.com
Website: https://www.sonsothunder.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: We don't need a Player (was Re: New(?) Idea for Standalones)

2021-04-13 Thread Ken Ray via use-livecode


> On Apr 13, 2021, at 5:28 AM, Andre Garzia via use-livecode 
>  wrote:
> 
> I like all that I read here. There are things that are really hard when 
> building standalone apps that I don’t think should be handled by LC HQ, such 
> as “adding AppleScript dictionary” to your app. This is harder than it seems 
> and it involves plist manipulation, fancy sdef xml creation, etc. This is too 
> large a product to develop with a small target base.
> 
> On the other hand, I think that the SB should create standalones that can 
> actually be deployed, this means that it should be able to handle 
> notarisation on the mac out-of-the-box.

Amen, brother! 

:)


Ken Ray
Sons of Thunder Software, Inc.
Email: k...@sonsothunder.com
Website: https://www.sonsothunder.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: "within graphic" question

2021-02-22 Thread Ken Ray via use-livecode
If you're willing to do something "hackish", you could do this:

on mouseDown
  lock screen
  show grc "mygraphic"
  put within(grc "mygraphic",the clickloc)
  hide grc "mygraphic"
  unlock screen
end mouseDown

:D

Ken


> On Feb 22, 2021, at 1:49 PM, jbv via use-livecode 
>  wrote:
> 
> Hi list,
> 
> I have a graphic made of a list of points. This graphic is opaque
> and invisible, its filled property is set to true (according to
> the doc).
> In my card script I have something like :
> on mousedown
>  put within(grc "mygraphic", the clickloc)
> end mousedown
> 
> but it always returns false, even when I click
> inside the clickable area of the graphic...
> What am I missing ?
> 
> Thanks in advance.
> jbv
> 
> ___
> 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