Reply to topic  [ 8 posts ] 
Opening a pdf file out of Nisus 
Author Message

Joined: 2007-04-12 14:59:36
Posts: 229
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


2014-04-07 07:36:18
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
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…

_________________
philip


2014-04-07 20:25:03
Profile

Joined: 2007-04-12 14:59:36
Posts: 229
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.


2014-04-08 04:38:14
Profile
User avatar

Joined: 2007-01-17 03:25:42
Posts: 729
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 3813 times ]


2014-04-08 05:36:55
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
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.


2014-04-08 13:27:05
Profile WWW
User avatar

Joined: 2007-01-17 03:25:42
Posts: 729
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.


2014-04-08 23:47:46
Profile
User avatar

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

_________________
philip


2014-04-09 01:58:24
Profile

Joined: 2007-04-12 14:59:36
Posts: 229
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"


2014-04-12 14:44:46
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 8 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software