Launching an App bring it frontmost paste text into Field ..

Deploying to Mac OS? Ask Mac OS specific questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
gstrekkie
Posts: 27
Joined: Tue Aug 20, 2013 11:43 pm

Launching an App bring it frontmost paste text into Field ..

Post by gstrekkie » Fri May 23, 2014 10:24 pm

Hi I've been beating my head against the wall for a few days now and am chasing my tail.

I cannot seem to get livecode to launch an app located in my /Applications Directory. I've tried open process and shell methods to no avail nothing happens no error, nothing I put an answer "Hi" in just to see if the code is executed and its I see "Hi" so its getting there. I am mystified as to what I am doing wrong I have tried so many different iterations I dont know where to start so I'm here. In a nutshell I want to accomplish the following...

Launch /Applications/QGIS.app
make sure its Frontmost
Manually Add a point in the shape layer by Hand
and then fill the 4 fields that need to get populated by my CSV file and datagrid(this part I have working), by pasting into 1 field and move to the next and so on

this should be a rather straight forward process but for some reason I cannot get it to work
I have been acheiving some results by cludging it by moving back forth with the mouse between qgis and my app then manually pasting each field(dont laugh desperate measures!) so if anyone can pity the helpless noob please feel free to show me the error of my ways (barring throwing out my macbook pro and becoming amish!) thanks for any pointers or snippits

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Launching an App bring it frontmost paste text into Fiel

Post by Simon » Fri May 23, 2014 11:40 pm

Hi gstrekkie,
It should just be
launch "QGIS.app"

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

gstrekkie
Posts: 27
Joined: Tue Aug 20, 2013 11:43 pm

Re: Launching an App bring it frontmost paste text into Fiel

Post by gstrekkie » Fri May 23, 2014 11:59 pm

Friga Fraga Stupid Son of a Gun That works just fine as long as I dont put "/Applications/QGIS.app" I wasnt going to even try that because it was way too simple a solution but I resolved to do my Due Diligence and give it the college try and VIOLA! thanks for the quick response and now im gonna grow a beard and become amish because I couldnt see the forest for the trees! so lesson learned "KISS" keep it simple stupid....

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Launching an App bring it frontmost paste text into Fiel

Post by Simon » Sat May 24, 2014 12:01 am

Glad you got it working :)

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

gstrekkie
Posts: 27
Joined: Tue Aug 20, 2013 11:43 pm

Re: Launching an App bring it frontmost paste text into Fiel

Post by gstrekkie » Sat May 24, 2014 2:50 am

OK so making QGIS frontmost Now works now I want to paste something into an active textbox so I tried putting an applescript into a text fields contents

I placed this...

tell application "System Events"
keystroke "v" using {command down}
end tell

and it did not paste the contents of the clipboard. if I manually pasted at this point it placed the correct value.

I tried and replaced it with another applescript...

beep
display dialog "Hello World! How about some more beeps?"
beep

the applescript responds with a beep and a dialog then another beep... so my app is calling applescript so what should I change to make this work? if there is a livecode method that can do this I would love to try it. Also I am using mavericks and I am going into preferences security and making sure my app is allowed to control the computer in accessibility any thoughts would be appreciated..

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Launching an App bring it frontmost paste text into Fiel

Post by bn » Sat May 24, 2014 9:03 pm

Hi gstrekkie,

I don't think you can just tell SystemEvents to paste.

Either QGIS is scriptable and you would then tell QGIS to do it or you would have to to GUI scripting, something that is quite involved since you would have to address the window by its internal address.

http://macscripter.net/

is a huge resource for appleScript.

Kind regards
Bernd

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Launching an App bring it frontmost paste text into Fiel

Post by [-hh] » Sat May 24, 2014 10:33 pm

..........
Last edited by [-hh] on Wed Aug 13, 2014 2:47 pm, edited 1 time in total.
shiftLock happens

gstrekkie
Posts: 27
Joined: Tue Aug 20, 2013 11:43 pm

Re: Launching an App bring it frontmost paste text into Fiel

Post by gstrekkie » Sun May 25, 2014 3:19 am

I did change the per app security settings in Mavericks to allow my app control prior to asking this question but it doesnt seem to make a difference. unless livecode apps perhaps use a different internal name that the os sees instead of what name is given when creating the executable or something like that?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Launching an App bring it frontmost paste text into Fiel

Post by Simon » Sun May 25, 2014 4:10 am

Hi gstrekkie,
I think Bernd was a little subtle in his answer I believe he meant:

Code: Select all

tell application "QGIS"
activate
keystroke "tab" --Get field attention
keystroke "v" using {command down}
end tell
I'm not much of an Applescripter so I don't guarantee that is correct.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

gstrekkie
Posts: 27
Joined: Tue Aug 20, 2013 11:43 pm

Re: Launching an App bring it frontmost paste text into Fiel

Post by gstrekkie » Sun May 25, 2014 6:26 am

Thanks for the help so far but for some reason just about anything I try is just not working. for instance I put in this code

Code: Select all

on menuPick pItemName
   switch pItemName
      case "Paste" 
         if the clipboard is "text" then 
       paste 
         answer the clipboard
      end if
      break
      case "Copy"
         
   end switch
end menuPick
logically one would expect that if the text field I clicked has focus and shows this popup menu which i then select paste should it not in fact paste into the text field? especially if the answer reports "text"??

I'm just not getting it at this point and its confusing me . I also tried a couple of versions just to make sure it wasnt the version of livecode no difference... wo is me!

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Launching an App bring it frontmost paste text into Fiel

Post by Simon » Sun May 25, 2014 6:39 am

Hi gstrekkie,
Do you know how to use "breakpoint" or the little red dot when clicking on the line number in the script editor?
It makes it easy to step through the code to see if what you think is happening is actually happening.

I ask this because I just did a simple test of exactly what you have and it did paste correctly into the liveCode field.
Note this is not QGIS.app as soon as you click on the stack QGIS.app and it's field will lose focus.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

gstrekkie
Posts: 27
Joined: Tue Aug 20, 2013 11:43 pm

Re: Launching an App bring it frontmost paste text into Fiel

Post by gstrekkie » Sun May 25, 2014 7:02 am

well i didnt get paste to work but I tried to skin the cat another way
and replaced

Code: Select all

on menuPick pItemName
   switch pItemName
      case "Paste" 
         if the clipboard is "text" then 
       paste 
         answer the clipboard
      end if
      break
      case "Copy"
         
   end switch
end menuPick
with

Code: Select all

on menuPick pItemName
   switch pItemName
      case "Paste" 
         if the clipboard is "text" then 
      put the clipboarddata into fld "ascript"
         answer the clipboard
      end if
      break
      case "Copy"
         
   end switch
end menuPick
and that works as one would expect... Curiouser and Curiouser. what on my system prevents the pasting from livecode???

gstrekkie
Posts: 27
Joined: Tue Aug 20, 2013 11:43 pm

Re: Launching an App bring it frontmost paste text into Fiel

Post by gstrekkie » Sun May 25, 2014 7:10 am

Sorry Simon I missed your post yes I am aware that the app would lose focus to launch qgis I was screwing with the paste onto my app window so I could paste snippits of applescript into the text field to try different applescripts to test them in order to eventually paste into QGIS hopefully Im not getting evyone as confused as me. If thats the case I apologize and I do appreciate the help that everyone is giving me. sometimes you get too close to the problem to see the solution and then it spreads like mold.. thanks again. I am continuing to chip away until I get it.

gstrekkie
Posts: 27
Joined: Tue Aug 20, 2013 11:43 pm

Re: Launching an App bring it frontmost paste text into Fiel

Post by gstrekkie » Sun May 25, 2014 8:41 am

Thanks Everybody who Helped!

I finally got it sorted and here is what I did.

first off I need to fill 4 fields for every GIS point I am adding in on a shapelayer in QGIS I am entering a few thousand points and it is beyond tedious any way you slice it. I also wanted to eliminate any possible typos on my part. so this is what it took to get it to work for me.

my program loads a csv file with all the intersections and system detectors.
I go to that point on the map and place a new point that in turn triggers a form with 4 fields on it and the first field is active. my app then fills that field passes a TAB keystroke to move to the next field fills the next and so on for all four.

Code: Select all

global theDataA
on mouseUp
   //shell ("/Applications/QGIS") 
   launch "QGIS.app"
   wait 10 milliseconds
   paste
   if "AppleScript" is among the lines of the alternateLanguages then
      
      //Build the Applescript
      
      //tell application "System Events"
      //keystroke “1234”
      //keystroke tab
      //delay 
      //end tell
      
      
      put "tell application "& Quote &"System Events" &quote& lf &"keystroke "& quote& theDataA["System ID"] & quote& lf &"keystroke tab" & lf & "delay " &lf& "end tell" into fld  "ascript"
      //Run the applscript and wait
      do  fld "ascript"  as AppleScript
      wait 1 milliseconds
      //empty the text field used to assemble the Applescript and wait again
      put empty into fld "ascript"
      wait 1 milliseconds
      //send # 2
      put "tell application "& Quote &"System Events" &quote& lf &"keystroke "& quote& theDataA["Number"] & quote& lf &"keystroke tab" & lf & "delay " &lf& "end tell" into fld  "ascript"
      do  fld "ascript"  as AppleScript
      wait 1 milliseconds
      put empty into fld "ascript"
      wait 1 milliseconds
      //send # 3
      put "tell application "& Quote &"System Events" &quote& lf &"keystroke "& quote& theDataA["Controller"] & quote& lf &"keystroke tab" & lf & "delay " &lf& "end tell" into fld  "ascript"
      do  fld "ascript"  as AppleScript
      wait 1 milliseconds
      put empty into fld "ascript"
      wait 1 milliseconds
      //send # 4
      put "tell application "& Quote &"System Events" &quote& lf &"keystroke "& quote& theDataA["Name"] & quote& lf &"keystroke tab" & lf & "delay " &lf& "end tell" into fld  "ascript"
      do  fld "ascript"  as AppleScript
      wait 1 milliseconds
      put empty into fld "ascript"
      wait 1 milliseconds
      beep
      
      
      
      
   end if
   wait 10 milliseconds
   Launch "COB Helper"
   
   
end mouseUp

hopefully this might help someone else and I wont feel like I wasted anyones time who was kind enough to help. now I can shave and go to sleep and put off being Amish a little while longer. Not to mentions keep my extremely expensive Macbook Pro! :) And also I mean no disrespect to the Amish!
So Good Night to all!
(especially Me!)

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Launching an App bring it frontmost paste text into Fiel

Post by Simon » Sun May 25, 2014 8:59 am

Congratulations!
And thank you for posting your solution.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply