Reply to topic  [ 5 posts ] 
How to open a linked file in it‘s own Application ? 
Author Message

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


2017-10-29 04:50:59
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
You could try this:
Code:
$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


2017-10-29 05:57:24
Profile

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


2017-10-30 09:38:41
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
phspaelti wrote:
You could try this:
Code:
$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:
Quote:
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.


2017-10-30 14:05:13
Profile WWW
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
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:
$linkCommmand = "alias://$path"

If you really want to capture an alias to the target file you should use the proper Link object command:
Code:
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.


2017-10-30 14:10:42
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 3 guests


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:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software