Script to launch PDF

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

pastrana
Posts: 17
Joined: Wed Jun 14, 2006 9:54 pm

Script to launch PDF

Post by pastrana »

How do I launch from rev Studio a PDF doc from an specific folder in mac or pc? I can't find a solution in the previous forum threads.
Thanks!
Benjamin
Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel »

Almost there, just by writing your subject :-)

Code: Select all

launch document "<the path to your PDF file>"
HTH,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
pastrana
Posts: 17
Joined: Wed Jun 14, 2006 9:54 pm

launch pdf

Post by pastrana »

I am really getting crazy.

I tried the script but nothing happens!

on mouseUp
launch "/cover.pdf"
end mouseUp

the PDf doc & stack are in the same directory and even the Preview mac application.

I am really anxious to use Revolution for a Big Project but this simple
tasks forces me to use Flash!

I have version STUDIO
2.7 build 197
TonyL
Posts: 24
Joined: Mon Aug 07, 2006 1:15 am

Post by TonyL »

Try removing the slash:

launch "cover.pdf"
Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel »

First of all, the Revolution engine will not automatically include the current stack's hard disk location in its search tree. So you may have to use a full path to your PDF file - which you can derive from the 'effective filename' of your stack.
Secondly, the 'launch document' variant was introduced in Revolution 2.7.1 build 236, so I'm afraid you'll have to stick with the 'launch' command. So we end up with the following script.

Code: Select all

on mouseUp
  put the effective filename of this stack into thePath
  set the itemDelimiter to "/"
  put "cover.pdf" into the last item of thePath
  lanch thePath
end mouseUp
HTH,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
pastrana
Posts: 17
Joined: Wed Jun 14, 2006 9:54 pm

NOTHING!

Post by pastrana »

Thansk JAN, I tried
and here is a small movie I recorder to show nothing happens with the script.

The movie executing script
http://www.sandovale.com/revolution/pdf.mov

THE STACK
http://www.sandovale.com/revolution/PDF.rev


THE PDF doc to launch
http://www.sandovale.com/revolution/battlechic


any help will be appreciated!

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

Post by Klaus »

As Jan already wrote in his first post: Use the correct syntax!

Code: Select all

...
launch DOCUMENT tPath
...
should do the trick.


Best

Klaus
Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark »

Hi,

You may find that the launch command is unreliable in older versions of Revolution. You might want to try the following script:

Code: Select all

set the itemDel to slash
put item 1 to -2 of the effective filename of me into myPath
put "/battlechic.pdf" after myPath
if the platform is "MacOS" then
  put revMacFromUnixPath(myPath) into myPath
  put "tell application 'Finder' to open item '" & myPath & "'" into myScript
  replace "'" with quote in myScript
  do myScript as AppleScript
else if the platform is "Win32" then
  replace slash with backslash in myPath
  put "start '' '" & myPath & "'" into myShell
  get shell(myShell)
end if
I didn't test this script, but the approach works.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
pastrana
Posts: 17
Joined: Wed Jun 14, 2006 9:54 pm

Getting error from script

Post by pastrana »

executing at 11:34:52 AM
Type Chunk: can't set property
Object Button
Line put item 1 to -2 of the effective filename of me into myPath
Hint mouseUp
pastrana
Posts: 17
Joined: Wed Jun 14, 2006 9:54 pm

Post by pastrana »

Hello Mark, I tried your script but then script (the bold line) gets highlited as an error.

on mouseUp
set the itemDel to slash
put item 1 to -2 of the effective filename of me into myPath
put "/battlechic.pdf" after myPath
if the platform is "MacOS" then
put revMacFromUnixPath(myPath) into myPath
put "tell application 'Finder' to open item '" & myPath & "'" into myScript
replace "'" with quote in myScript
do myScript as AppleScript
else if the platform is "Win32" then
replace slash with backslash in myPath
put "start '' '" & myPath & "'" into myShell
get shell(myShell)
end if
end mouseUp
SparkOut
Posts: 2987
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut »

I think "me" in this context is meant to refer to the stack - when using "me" in the mouseUp handler you will be using it in the context of a button not a stack.

D oes it work if you replace that line as follows?

Code: Select all

put item 1 to -2 of the effective filename of this stack into myPath
Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark »

Hello pastrana,

"of me" should be "of this stack".

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
pastrana
Posts: 17
Joined: Wed Jun 14, 2006 9:54 pm

Post by pastrana »

ALELUYA!

Thanks Mark!

Now it worked!

:D :D :D :D :D :D :D :D
Stormy1
Posts: 31
Joined: Tue Jul 14, 2009 1:47 pm

Post by Stormy1 »

Hi Guys

I've tried this script in my program and it works fine while in Revolution but when I create a standalone, nothing happens?

Is this something to do with the name of the standalone?

Not sure why its happening. Any ideas?

Thanks
Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark »

Dear Stormy1,

You might want to add a few lines to check that your file actually exists.

Code: Select all

if not (there is a file myPath) then
  beep
  answer error "Can't find file" && myPath
else
  -- remainder of script
end if
Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Post Reply