Reply to topic  [ 8 posts ] 
Finder info window of Nisus document 
Author Message

Joined: 2007-04-12 14:59:36
Posts: 229
I want to use a macro to see the Finder's information window of the Nisus document on top.
I tried this:


Code:
$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?


2013-09-28 05:10:20
Profile
User avatar

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


2013-09-29 17:05:31
Profile
User avatar

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


2013-09-29 17:31:39
Profile

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


2013-09-30 02:04:47
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
I'm no expert on AppleScript either, but after some googling I put this together:
Code:
$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


2013-09-30 12:26:27
Profile WWW
Official Nisus Person
User avatar

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


2013-09-30 12:28:35
Profile WWW

Joined: 2007-04-12 14:59:36
Posts: 229
Works fine. Thank you for your help.


2013-09-30 15:53:37
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
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:
$doc = Document.active
$docPath = $doc.filePath.expandedFilePath

That same code could be broken down into:
Code:
$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.


2013-10-01 13:05:51
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 8 posts ] 

Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 2 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