How to open a linked file in it‘s own Application ?

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

How to open a linked file in it‘s own Application ?

Post by js »

Nisus „Add link to file“ menug works differently after the introduction of sandbox security
Before, the menu "edit link" let you edit the link. Now it shows you only the last known folder with the linked file inside.
Still: if you select the link and paste it into the Terminal, you see what you earlier could edit:
It appears as „file:///~file path.ending“ like f.e. ending with „path.mmap“ for a MindManager file.

Now here is my question:
Clicking the link in Nisus opens the MindManager file (as expected).
Using open „file:///~file path.ending“ in the terminal does the same (as expected).
But using

Code: Select all

open "file:///~file path.mmap"
in a Nisus macro tries to open the MindManager file as Nisus text.

How can you open a linked file from a Nisus macro in it‘s own application?
(Which is what Nisus macro "open URL" does).
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: How to open a linked file in it‘s own Application ?

Post by phspaelti »

You could try this:

Code: Select all

$link = Link.newWithAliasToFileAtPath '~file path.mmap'
$link.activate @undefined
There is something in the Macro Reference about the @undefined business being "not recommended", but I'm not sure I understand what the problem is. But frankly I'm not even sure I understand why the syntax of this command looks as it does.
philip
js
Posts: 259
Joined: 2007-04-12 14:59:36

Re: How to open a linked file in it‘s own Application ?

Post by js »

Thank you Philip,

Your macro works well. If the file name has escape characters I use it with double quotes.
Thinking further about the "open URL" command, I find now that it also possible to use it for all files, non Nisus opening in their own application. Like so:

Code: Select all

$path = Choose File
open URL "file:///$path"
While the Nisus “Add link to file…” Menu lets you insert links that open in their own application, I find it handy to see beforehand whether the link to a file other than Nisus. Profiting from your help I wrote this macro to achieve this, in case anybody is interested:

Code: Select all

$path = Choose File # select the path manually
$docType = $path.filePathExtension # for example .pdf
$linkCommmand = "alias://$path"
$docName = $path.lastFilePathComponentWithoutExtension

$linkGreen = Color.newWithHexTriplet '589E06' # color the doctype
Set Text Color $linkGreen
Type Text "✩$docType"
Remove Attributes and Styles
Type Text " "
Type link $linkCommmand, $docName
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: How to open a linked file in it‘s own Application ?

Post by martin »

phspaelti wrote:You could try this:

Code: Select all

$link = Link.newWithAliasToFileAtPath '~file path.mmap'
$link.activate @undefined
There is something in the Macro Reference about the @undefined business being "not recommended", but I'm not sure I understand what the problem is. But frankly I'm not even sure I understand why the syntax of this command looks as it does.
The Link object's activate command works best if you pass in the relevant Document object instead of @undefined. The macro reference discusses why:
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")
I'm not sure relative link paths are used/valid anymore, but here's another example: consider an intra-document link like "#bookmark_name". If you don't pass the Document object then the link can't be resolved to the target named bookmark.

But all this is irrelevant for links to an external file, as js is asking about here. There's no need to pass in the source document for those types of links.
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: How to open a linked file in it‘s own Application ?

Post by martin »

I'm glad js has solved the problem, but one final tip. It is generally not good to construct links to files manually like this:

Code: Select all

$linkCommmand = "alias://$path"
If you really want to capture an alias to the target file you should use the proper Link object command:

Code: Select all

Link.newWithAliasToFileAtPath $path
That will also ensure that a security-scoped bookmark is captured for the target, allowing Nisus Writer to maintain access with sandboxing. Otherwise you might find that the links work for a time, but later you need to re-authorize access.

Although actually, if you're just going to later pass these file paths to the "Open URL" command, then Nisus Writer's access to the target probably won't matter, since that opens the target externally.
Post Reply