Finder info window of Nisus document

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

Finder info window of Nisus document

Post by js »

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

Code: Select all

$doc = Document.active
$doc = $doc.filePath

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

Run AppleScript $code
It does not work. What did I do wrong?
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Finder info window of Nisus document

Post by phspaelti »

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

Re: Finder info window of Nisus document

Post by phspaelti »

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?

Code: Select all

$doc = Document.active
$path = $doc.filePath
$info = File.infoAtPath $path
$info_list = ''
foreach $i_key, $i_val in $info
	$info_list &= "$i_key\t$i_val\n"
end
prompt $info_list
philip
js
Posts: 259
Joined: 2007-04-12 14:59:36

Re: Finder info window of Nisus document

Post by js »

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.
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Finder info window of Nisus document

Post by martin »

I'm no expert on AppleScript either, but after some googling I put this together:

Code: Select all

$doc = Document.active
$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
End
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Finder info window of Nisus document

Post by martin »

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

Re: Finder info window of Nisus document

Post by js »

Works fine. Thank you for your help.
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Finder info window of Nisus document

Post by martin »

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:

Code: Select all

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

Code: Select all

$doc = Document.active
$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.
Post Reply