Opening a pdf file out of Nisus

Get help using and writing Nisus Writer Pro macros.
Post Reply
js
Posts: 259
Joined: 2007-04-12 14:59:36

Opening a pdf file out of Nisus

Post by js »

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: Select all

$code = "
	set myPath to "~/.../.pdf"
tell application "Finder" to open myPath as alias
	end tell
"
Run AppleScript $code
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Opening a pdf file out of Nisus

Post by phspaelti »

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: Select all

$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…
philip
js
Posts: 259
Joined: 2007-04-12 14:59:36

Re: Opening a pdf file out of Nisus

Post by js »

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.
User avatar
Hamid
Posts: 777
Joined: 2007-01-17 03:25:42

Re: Opening a pdf file out of Nisus

Post by Hamid »

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':
DMopenPDF.gif
DMopenPDF.gif (14.97 KiB) Viewed 14404 times
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Opening a pdf file out of Nisus

Post by martin »

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.
User avatar
Hamid
Posts: 777
Joined: 2007-01-17 03:25:42

Re: Opening a pdf file out of Nisus

Post by Hamid »

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.
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Opening a pdf file out of Nisus

Post by phspaelti »

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: Select all

$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.
philip
js
Posts: 259
Joined: 2007-04-12 14:59:36

Re: Opening a pdf file out of Nisus

Post by js »

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

Code: Select all

Open URL "file:///... path ... .pdf"
Post Reply