Link command fails in mac-standalone

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
kresten
Posts: 153
Joined: Tue Sep 30, 2008 3:01 pm
Contact:

Link command fails in mac-standalone

Post by kresten » Mon Jan 14, 2013 3:35 pm

Hi
I have some options for users to produce link-buttons to folders, programs and files in their diary. These options works nicely also in standalones on windows, and in the prototype Mac version, but they fail in a funny way in Mac standalones, because I get an error message saying, that they do not find...and then specifies the full and exact address of the file they say they cannot find..


button ”Filetype”:
on mouseUp
if (there is a file (the cFile of me)) then
if the platform is "MacOS" then
put revmacfromunixpath(the cFile of me) into myFile
put "tell application 'Finder'" & return & "activate" & return & \
"open file'" & myFile & quote & return & "end tell" into myScript
replace "'" with quote in myScript
replace slash with colon in myScript
do myScript as AppleScript
else if the platform is "Win32" then
put "start '' '" & the cFile of me & quote into myShell
replace "'" with quote in myShell
get shell(myShell)
else beep
else if the cFile of me is empty then
beep
answer error "Sorry, no File has been set." with "Okay"
else
beep
answer error "Sorry, I can't find file" && the cFile of me
end if
....etc

The script of the link to program is slightly different:

on mouseUp
if (there is a file (the cFile of me) or there is a folder (the cFile of me)) then
put empty into rslt
if the platform is "MacOS" then
put revmacfromunixpath(the cFile of me) into myFile
put "tell application 'Finder'" & return & "activate" & return & \
"open file'" & myFile & quote & return & "end tell" into myScript
replace "'" with quote in myScript
replace slash with colon in myScript
do myScript as AppleScript
put the result into rslt
else if the platform is "Win32" then
put "start '' '" & the cFile of me & quote into myShell
replace "'" with quote in myShell
get shell(myShell)
put the result into rslt
else
beep
end if
if rslt is empty then
close stack "stormaske"
set the iconic of stack "phenomenalog" to true
else
beep
answer error "Sorry, an error occurred" with "OK"
end if
else if the cFile of me is empty then
beep
answer error "Sorry, no File has been set." with "Okay"
else
beep
answer error "Sorry, I can't find file" && the cFile of me
end if
ikonide

end MouseUp

I must admit that I don't understand what the reference to "result" and rslt means, perhaps an early attempt to repair the bug.
But as even the link to file doesn't function I would disregard it, until further.
Hope somebody have an idea how to repair
best regards
Kresten Bjerg (www.phenomenalog.dk)

Klaus
Posts: 14206
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Link command fails in mac-standalone

Post by Klaus » Mon Jan 14, 2013 4:46 pm

Hi Kresten

try this, crossplatform and pure Livecode :D

Code: Select all

on mouseUp
  put the cFile of me into tFile

## First check for something that will need to EXIT the handler, this will avoid too many nested "IF... THEN..." cases:  
  if tFile = empty then
    beep
    answer error "Sorry, no File has been set." with "Okay"
    exit mouseup
  end if
  
  if there is NOT a file tFile OR there is NOT a folder tFile then
    beep
    answer error "Sorry, I can't find file" && the cFile of me
    exit mouseup
  end if
  
  ## Use LAUNCH instead of messing around with other scripting languages :-)
  launch document tFile
  if the result <> EMPTY then
    answer error "Sorry, an error occurred" with "OK"
    exit mouseup
  end if
 
  ## File/folder successfully LAUNCHED, now do the rest: 
  close stack "stormaske"
  set the iconic of stack "phenomenalog" to true

  ## more code here...
end MouseUp
Best

Klaus

kresten
Posts: 153
Joined: Tue Sep 30, 2008 3:01 pm
Contact:

Re: Link command fails in mac-standalone

Post by kresten » Tue Jan 15, 2013 3:40 pm

Thank you for your suggestion, but I tried it out, and I get exactly the same paradoxical errormessage, specifying the adress and saying, that it cant find the file. Same result from linking an .app, a .html file or a .txt file. A parallel link-to-folder function works fine.
The new script even doesnt work in the clone (the livecode stack)- = gives the same silly reply. :cry:

Klaus
Posts: 14206
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Link command fails in mac-standalone

Post by Klaus » Tue Jan 15, 2013 4:11 pm

Hi Kresten,

how do you "save" the file that the user selected?
You must take it "as is" as returned from the "answer file..." dialog, no "revMacFromUnixPath" etc.!


Best

Klaus

kresten
Posts: 153
Joined: Tue Sep 30, 2008 3:01 pm
Contact:

Re: Link command fails in mac-standalone

Post by kresten » Wed Jan 16, 2013 12:13 pm

Thanks for advice, but the answer script is only:

if it is "File" then
answer file ("Link to which file")
if it is empty then
exit link
else
put it into filesti
set itemdelimiter to "/"
put last item of filesti into btnname
select button "Filetype"
copy
end if
if range is "all" then
start editing group id 8679
paste
stop editing
end if
if range is "one" then
paste
end if
set the name of it to btnname
set the width of btn btnname to the formattedWidth of btn btnname
set the height of btn btnname to the formattedheight of btn btnname
set the textcolor of it to "Black"
set the loc of it to landing
set the visible of it to true
set the cFile of it to filesti
end if

By the way I had difficulty finding anything about the cfile concept in live code library

Klaus
Posts: 14206
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Link command fails in mac-standalone

Post by Klaus » Wed Jan 16, 2013 12:40 pm

Hi Kresten,
kresten wrote:...
set the name of it to btnname
set the width of btn btnname to the formattedWidth of btn btnname
set the height of btn btnname to the formattedheight of btn btnname
set the textcolor of it to "Black"
set the loc of it to landing
set the visible of it to true
set the cFile of it to filesti
end if
...
Looks OK.

Did you check the custom property to contain the correct filepath in the end?
I am just wildly guessing, sincew I have o clue so far...
kresten wrote:By the way I had difficulty finding anything about the cfile concept in live code library
There is no "cFile concept"! 8)
This is just about storing and retrieving info to and from a custom property of any object (control)! :D


Best

Klaus

kresten
Posts: 153
Joined: Tue Sep 30, 2008 3:01 pm
Contact:

Re: Link command fails in mac-standalone

Post by kresten » Wed Jan 16, 2013 12:53 pm

Yes !
And even in the live-code stack it doesnt work.
Whereas the original script (with apple script and result) does work in live-code stack, only not in standalones
best
Kresten

Klaus
Posts: 14206
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Link command fails in mac-standalone

Post by Klaus » Wed Jan 16, 2013 1:14 pm

Hi Kresten,

hmm, no more ideas...

I just tesetd this on my Mac:
1. set the cFile of a button to a user selected file
2. changed the NAME of the button to that filename
3. opened the file (just like doubleclicked in the FINDER) with:
...
put the cFile of me into tFile
launch document tFile
## Success!
...

Best

Klaus

kresten
Posts: 153
Joined: Tue Sep 30, 2008 3:01 pm
Contact:

Re: Link command fails in mac-standalone

Post by kresten » Wed Jan 16, 2013 2:07 pm

OK
I tried to comment(remove) :
if there is NOT a file tFile OR there is NOT a folder tFile then
beep
answer error "Sorry, I can't find file" && the cFile of me
exit mouseup
end if
and now at least it works in livecode !!!!
-how could that corrupt the handler ????

Hurrah !!! It also works in the standalones !!!!!!!
Klaus, You have helped me more times than i can remember. !
I am so gratefull !
Hope to stay in contact--- perhaps skype. My skype is "bethkresten" :D

Klaus
Posts: 14206
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Link command fails in mac-standalone

Post by Klaus » Wed Jan 16, 2013 2:18 pm

Dag Kresten,

my pleasure :D


Best

Klaus

Post Reply