Finder info window of Nisus document
Page 1 of 1

Author:  js [ 2013-09-28 05:10:20 ]
Post subject:  Finder info window of Nisus document

I want to use a macro to see the Finder's information window of the Nisus document on top.
I tried this:

$doc =
$doc = $doc.filePath

$code = '
tell application "Finder"
open information window of document "$doc"
end tell'

Run AppleScript $code

It does not work. What did I do wrong?

Author:  phspaelti [ 2013-09-29 17:05:31 ]
Post subject:  Re: Finder info window of Nisus document

$doc is a variable in Nisus Macro language, so Applescript will have no idea what to do with it. You will have to assign the $code in a way that interpolates the $doc variable. So try using double quotes instead. Then use back slash before the double quotes inside the $code.
Also try using a prompt to see if the $code variable is assigned the way you want it.

Author:  phspaelti [ 2013-09-29 17:31:39 ]
Post subject:  Re: Finder info window of Nisus document

After trying my suggested improvements the macro switched to the finder, but did not work. I'm not an expert at AppleScript so I don't know what the problem is.
But here is another idea. Nisus Macro language can access file info too. So how about this?
$doc =
$path = $doc.filePath
$info = File.infoAtPath $path
$info_list = ''
foreach $i_key, $i_val in $info
   $info_list &= "$i_key\t$i_val\n"
prompt $info_list

Author:  js [ 2013-09-30 02:04:47 ]
Post subject:  Re: Finder info window of Nisus document

Thank you Philip.
As you say the problem is how to make applescript interpret the variable passed from the Nisus macro.
Unfortunately the Reference provided by Nisus does not include a helpful example for this situation.

Your suggestion to read the file info is certainly interesting for some purposes. Mine is to see the uppermost window of the finder info window.
That's where spotlight can read our keywords now, and where the tags of the upcoming Mavericks operating system will appear.

Author:  martin [ 2013-09-30 12:26:27 ]
Post subject:  Re: Finder info window of Nisus document

I'm no expert on AppleScript either, but after some googling I put this together:
$doc =
$docPath = $doc.filePath.expandedFilePath

$code = "
    set docAlias to POSIX file \"$docPath\" as alias
    tell application \"Finder\" to open information window of docAlias

$errorMessage = ''
$success = Run AppleScript $code, $errorMessage
If ! $success
   Prompt 'AppleScript failed.', $errorMessage

Author:  martin [ 2013-09-30 12:28:35 ]
Post subject:  Re: Finder info window of Nisus document

Quick note: if you copy-paste that code into a NWP macro to run it, you'll have to strip the non-breaking spaces that are part of the forum's HTML. AppleScript doesn't seem to handle them.

Author:  js [ 2013-09-30 15:53:37 ]
Post subject:  Re: Finder info window of Nisus document

Works fine. Thank you for your help.

Author:  martin [ 2013-10-01 13:05:51 ]
Post subject:  Re: Finder info window of Nisus document

Happy to help!

As Philip mentioned, the key was converting the document into something AppleScript could understand. The NWP macro Document object only has any meaning to NWP macro code. The Finder's AppleScript suite (apparently) likes to work with Mac aliases, which are a special way of identifying files using meta-data. Basically an alias describes a file in such a way that the original can be identified even if it is moved or renamed, in contrast to a file path which does not have such capabilities. Anyways, for this purpose an alias is just a way of identifying a file.

So, starting with the active Document object, we get its file path:
$doc =
$docPath = $doc.filePath.expandedFilePath

That same code could be broken down into:
$doc =
$docPath = $doc.filePath
$docPath = $docPath.expandedFilePath

The second command "expandedFilePath" simply makes sure that no abbreviations are present in the path, eg: it converts the "~" character into the actual user's home folder path. We do this because even though these abbreviations are widely supported (eg: by the NWP macro language, OSX command line, etc) it seems that AppleScript does not tolerate them.

Once we have a full expanded file path (a POSIX path), it is converted into a Mac alias using AppleScript.

Anyways, I hope that helps explain some things.

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group