Page 1 of 1

Launch document problem

Posted: Tue Mar 20, 2007 6:05 am
by troyhen
I'm writing a cross platform stack. It has to run on at least Mac OSX and Windows XP. Other platforms are a bonus. When I get it working, I need to burn it on a hybrid CD format, so that I can ship a single CD for both platforms.

The stack needs to open the user guide (a PDF file) from the same folder/directory as the stack then the user clicks a certain button. I need this to work from the hard drive (on both platforms) as well as from the CD once it's burned. And I need it to work in development mode as well as on the player. Obviously, I cannot use an absolute path to the file; it must be relative to the stack.

In order to solve the development mode problem I use the following script in preOpenStack:

Code: Select all

  get the filename of this stack
  split it using "/"
  delete variable it[number of lines of the keys of it]
  combine it using "/"
  set the defaultFolder to it
The goal of this is to force revolution to always look for files in the same folder as the stack. This appears to work fine on both PC and Mac.

I also use the following script to find the user guide (for opening later), which can have several name variations as well as the revision:

Code: Select all

  global guide
  repeat with x = 1 to the number of lines of the files
    get line x of the files
    if it contains "User's Guide" then
      put it into guide
      exit findGuide
    end if
  end repeat
This also appears to work correctly on both platforms.

When the button is clicked here is how I open the file:

Code: Select all

  global guide
  if guide is empty then
    answer "I can't find the User Guide. Please check the disk."
  else
    launch document guide
    if the result is not empty then
      answer the result && guide && "in" the defaultFolder
    end if
  end if
On the PC this works great. Acrobat reader is launched and the User Guide is opened. However, on the Mac I always get an error: "can't open file" along with the correct file name that was found earlier and the correct path. For some reason Mac Revolution can't open the file but the PC version can. BTW, I can double-click the PDF on both platforms and it opens just fine. Also, I am only testing with the Player on the Mac. On the PC I have both Rev Studio and the Player, and both work fine.

Why can I correctly find the file but not launch it on the Mac? Is there a way to get more error/debug information out of Revolution than just "can't open file"? Any help or suggestions would be greatly appreciated.

TIA,
Troy

Posted: Tue Mar 20, 2007 12:22 pm
by Mark
Hi Troy,

There is no reason to make such a complex script. Just get the path to your stack, change it by replacing the last part of the path with the file name, and launch.

set the itemdel to slash
put item 1 to -2 of the effective filepath of this stack into myPath
put "User Guide" after myPath
launch document myPath

You might want to replace "this stack" with "me" or "stack <short name of your stack>".

Best regards,

Mark

Posted: Tue Mar 20, 2007 8:48 pm
by troyhen
Thanks for the tip, Mark. It's obvious I am new to Revolution, though I have many years of programming experience. I can usually figure out a way to get things done, even if it's not the most straight forward.

How did you learn about "effective filepath" of this stack? I can't find that documented anywhere.

You have simplified the first of my three functions. But since I do not know the exact name of the user guide until runtime, I have to keep the function to locate it. (We keep revising it and changing the name slightly.) Here's what the first handler looks like now:

Code: Select all

on cdHere
  set the itemdel to slash
  set the defaultFolder to item 1 to -2 of the effective filepath of this stack
end cdHere
Even though you have simplified my cdHere handler considerably, it did not solve my real problem. The document still will not open/launch on the Mac.

Any other ideas? Anyone else?

Posted: Tue Mar 20, 2007 9:10 pm
by Mark
Hi Troy,

You need to make sure that the variable "guide" is correct. In my example, I forgot a slash. Adjusting it to find the user guide results in the following script:

Code: Select all

set the itemdel to slash
put item 1 to -2 of the effective filepath of this stack into myPath
set the defaultFolder to myPath
put the file into myFileList
filter myFileList with "*User's Guide*"
if number of lines of myFileList > 0 then
  put slash & myFileList after myPath
  launch document myPath 
else
  beep
  answer error "Sorry, can't find the user guide." with "Okay"
end if
This is untested, I hope this works.

Best,

Mark

Posted: Tue Mar 20, 2007 9:38 pm
by BvG
You say that you use "the Player", if that is the player from RunRev, you migth want to make sure that it's not in secure mode.

Secure mode prohibits access to the filesystem and script execution, so that might be the problem here. More info about secureMode is in the dictionary of rev.

You can disable secure mode by clicking the rev icon of the player, you need to quit and restart the player for it to take effect.

You also asked where mark found the "effective filename", that is in the dictionary, under "filename of stack", in the middle of the article (well hidden, eh?).

Posted: Tue Mar 20, 2007 11:45 pm
by troyhen
Yes, I'm using the free Revolution Player downloaded from www.runrev.com. I read about secureMode. But the docs say that secureMode cannot be set to false once it's set to true. I never set it to true or false. If type

Code: Select all

 put the secureMode
in the message box in Rev Studio (on Windows) it prints false. I don't have Studio on the Mac, so I can't try that there. (I'm not allowed to install anything on this Mac because it's borrowed, for the short term of this project, which was supposed to be "real easy in Revolution". :lol:)

Please tell me what you mean by
clicking the rev icon of the player
? Even though I don't think it's on, secureMode could possibly be my problem. I tried Get Info on Revolution Player, but the Mac Finder knows nothing about secureMode. When the Player is running clicking it's icon on the task bar does nothing except bring the program to the front, if it's not already. I guess I can't find the Rev icon you are referring to.

Thanks,
Troy

Posted: Wed Mar 21, 2007 3:48 am
by BvG
The secureMode can't be set to false once it's set to true, unless you restart the application afterwards.

By default, the Rev Player used to ship with secureMode enabled. It had a window and in that window an Icon one could click to access some settings. It seems the new Rev Player ships with secureMode set to false (I just tested that). So it must be something else.

can't open file means almost always that the file specified doesn't exit.
I tried this script and it worked for me, from the player:

Code: Select all

set the itemdelimiter to slash
put item 1 to -2 of the effective filename of this stack into x
launch document (x & "/" & "blogger-api.txt") 
put the result into field 2
when blogger-api.txt was in the same folder as my stack. I also changed the script proposed by Mark a bit, and it works like that for me. If that code doesn't work for you, then I don't know either...

Code: Select all

set the itemdel to slash
put item 1 to -2 of the effective filename of this stack into myPath
set the defaultFolder to myPath
put the files into myFileList
filter myFileList with "*license*"
if number of lines of myFileList > 0 then
  put slash & line 1 of myFileList after myPath
  launch document mypath
  if the result <> "" then
    answer error the Result as sheet
  end if
else
  beep
  answer error "Sorry, can't find the user guide." as sheet
end if
[/b]