nisus.com
https://www.nisus.com/forum/

Opening a pdf file out of Nisus
https://www.nisus.com/forum/viewtopic.php?f=17&t=5701
Page 1 of 1

Author:  js [ 2014-04-07 07:36:18 ]
Post subject:  Opening a pdf file out of Nisus

I want to open a pdf file from Nisus.
With the link command this is possible. But I would like to open the pdf file with a macro.
Document.open [filePath] can do it, but the pdf file is first transformed into rtf, which is not what I want.
Is the only way then to have a Nisus Macro call Applescript ?
I tried, but found it more difficult than expected. What is wrong with the following:

Code:
$code = "
   set myPath to "~/.../.pdf"
tell application "Finder" to open myPath as alias
   end tell
"

Run AppleScript $code

Author:  phspaelti [ 2014-04-07 20:25:03 ]
Post subject:  Re: Opening a pdf file out of Nisus

Of course, since you want some other application to do the opening, it's a bit strange to ask Nisus to do it :P

But it turns out you can do what you want like this:
Code:
$tempLink = Link.newWithFilePath '~/myfilepath/myfile.pdf'
$tempLink.activate undefined

Note that you have to specify undefined for the argument, since the link is not in a document. But here is what the Macro Reference says:
Nisus Macro Reference wrote:
In order to resolve links properly, you must pass the document this link is contained within. If the link is not applied in a document, you may pass the undefined value instead, but this is not recommended because it may fail (consider a relative link like "images/blerg.png").

So I guess this works right as long as you take care to use an unambiguous path…

Author:  js [ 2014-04-08 04:38:14 ]
Post subject:  Re: Opening a pdf file out of Nisus

Well Thank you. This works. I have no idea why.
I first understood that I should keep my original macro with the applescript in it, and change the path in the form you wrote me. But this is not the case. The 2 lines you send suffice to open the pdf. I still hope somebody will write an introduction to Nisus macros with some dozen simple examples to learn from them.

BTW To open a pdf from inside Nisus can be quite useful. Let's say you have a dictionary on a pdf file which you want to consult regularly while writing texts on Nisus. – Or simply because Nisus allows you to attribute multi character abbreviations to call a file. These are easy to memorize. Keyboard Maestro f.e. can't do that.

Author:  Hamid [ 2014-04-08 05:36:55 ]
Post subject:  Re: Opening a pdf file out of Nisus

js wrote:
[...]
BTW To open a pdf from inside Nisus can be quite useful. Let's say you have a dictionary on a pdf file which you want to consult regularly while writing texts on Nisus. [...].


You can open a PDF from NWP in Document Manager by selecting its icon in Document Manger, right-clicking and applying 'Open in Default Application':
Attachment:
DMopenPDF.gif
DMopenPDF.gif [ 14.97 KiB | Viewed 3794 times ]

Author:  martin [ 2014-04-08 13:27:05 ]
Post subject:  Re: Opening a pdf file out of Nisus

js wrote:
BTW To open a pdf from inside Nisus can be quite useful. Let's say you have a dictionary on a pdf file which you want to consult regularly while writing texts on Nisus. – Or simply because Nisus allows you to attribute multi character abbreviations to call a file. These are easy to memorize. Keyboard Maestro f.e. can't do that.

One enhancement to Hamid's suggestion: once you have a file in the Document Manager you can assign it a keyboard shortcut. Just visit Nisus Writer's "Menu Keys" preference pane and find the document's entry on the menu File > Open from Document Manager. That way you won't have to use the mouse and Document Manager window.

Author:  Hamid [ 2014-04-08 23:47:46 ]
Post subject:  Re: Opening a pdf file out of Nisus

martin wrote:
[...]
One enhancement to Hamid's suggestion: once you have a file in the Document Manager you can assign it a keyboard shortcut. Just visit Nisus Writer's "Menu Keys" preference pane and find the document's entry on the menu File > Open from Document Manager. That way you won't have to use the mouse and Document Manager window.

Doing what you say will open the pdf file not in its default application but as a NWP converted file.

Author:  phspaelti [ 2014-04-09 01:58:24 ]
Post subject:  Re: Opening a pdf file out of Nisus

Hello js,
somewhat belatedly an explanation.
js wrote:
Well Thank you. This works. I have no idea why.

It works for the same reason that clicking on a link works. The macro creates a link, but then rather than placing it in a document, it 'activates' it, which is the same as clicking on it.

As for your applescript version, there seem to be a number of issues. The most glaring is the problem with using quotes. Since your $code variable includes quotes you would need to escape them for things to go through. Then there is the whole business about how applescript deals with paths and filenames. You'd figure since that kind of thing is applescript's bread and butter it would be easy, but I can never do this without first spending half an hour studying the manual.
Anyhow rewriting the code like this worked for me:
Code:
$code = "
set myPath to POSIX file \"Users/me/Documents/mypath/myfile.pdf\"
tell application \"Finder\" to open myPath as alias
"
Run AppleScript $code

Apparently if the tell is a single line you don't need (can't use) an end tell. The path must be a full path, and you must use the POSIX file.

Author:  js [ 2014-04-12 14:44:46 ]
Post subject:  Re: Opening a pdf file out of Nisus

Good to know how the macro works, thank you. I meanwhile realize that the problem can also be solved with

Code:
Open URL "file:///... path ... .pdf"

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/