on appleEvent on LC 6 vs LC 7

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

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

on appleEvent on LC 6 vs LC 7

Post by Mag » Thu Sep 17, 2015 8:54 pm

On a Mac Standalone I use this script to learn about what interaction was made by the user when the standalone opens:

Code: Select all

on appleEvent pClass, pID
if pClass is "aevt" then
      if pID is "odoc" then // file opened on the Finder
         request appleEvent data
         put it into tFilePath
         openDocument tFilePath
      else if pID is "pdoc" then // file printed on Finder
         request appleEvent data
         put it into tFilePath
         printDocument tFilePath
      else if pID is "oapp" then // app opened on the Finder
         put "YES" into createNewWindow
      else
         pass appleEvent
      end if
   else
      pass appleEvent
   end if
end appleEvent
Then in openStack if I find "YES" in createNewWindow, I create the new window (I clone a stack).

All worked fine in LiveCode 6, but compiling with LC 7 I get that the openStack message happens before the appleEvent so I find the variable createNewWindow empty.

Is something changed between 6 and 7 about appleEvent handling? Or maybe it's just that my code is not so reliable how I hoping? :roll:


PS
How to create an application that opens when you drag a file onto it
http://lessons.runrev.com/m/4071/l/1592 ... le-onto-it

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3345
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: on appleEvent on LC 6 vs LC 7

Post by bn » Fri Sep 25, 2015 10:13 am

Hi Mag,

I tried this script and it works with LC 7. I defer the testing with a send in time command

my code is just to test if it works, otherwise pointless.

Code: Select all

local createNewWindow

on appleEvent pClass, pID
   if pClass is "aevt" then
      if pID is "odoc" then // file opened on the Finder
         request appleEvent data
         put it into tFilePath
         openDocument tFilePath
      else if pID is "pdoc" then // file printed on Finder
         request appleEvent data
         put it into tFilePath
         printDocument tFilePath
      else if pID is "oapp" then // app opened on the Finder
         put "YES" into createNewWindow
         put "gotEvent" into field "fInfo" -- check if it ever gets here, create field "fInfo"
      else
         pass appleEvent
      end if
   else
      pass appleEvent
   end if
end appleEvent

on opencard
 send putTime to me in 200 milliseconds
end opencard

on putTime
   if createNewWindow = "Yes" then
      put the long time into field "fRes" -- check if it works, create field "fRes"
   end if
end putTime
Kind regards
Bernd

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: on appleEvent on LC 6 vs LC 7

Post by Mag » Fri Sep 25, 2015 2:46 pm

Thank you so much Bernd, I will try your code!

Post Reply

Return to “Mac OS”