locking / unlocking the front file

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

locking / unlocking the front file

Post by js » 2010-07-18 05:35:18

I sometimes need to make an addition to a locked file, and lock it again. Is it possible to do this for the front file with a Nisus macro? If not: Can it be done by executing a shell file with a Nisus macro?

Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: locking / unlocking the front file

Post by Kino » 2010-07-18 07:08:42

For that purpose I'm using the macro below, to which I just added some commands for verifying the existence of SetFile and GetFileInfo which are required.

Code: Select all

$doc = Document.active
if $doc == undefined
	exit 'No open document, exiting...'
end

$path = $doc.filePath
if $path == undefined
	exit 'The frontmost document has never been saved, exiting...'
end
$locked = undefined

Set Exported Perl Variables 'path', 'locked'
Begin Perl
	chomp ($SetFile = `which SetFile`);
	chomp ($GetFileInfo = `which GetFileInfo`);
	if ( $SetFile && $GetFileInfo) {
		chomp ($locked = `GetFileInfo -al "$path"`);
		if ( $locked == 1 ) {
			`SetFile -a l "$path"`;
			$locked = 'unlocked';
		} else {
			`SetFile -a L "$path"`;
			$locked = 'locked';
		};
	};
end

if $locked == undefined
	exit "SetFile or GetFileInfo not found in \$PATH.\nYou may need installing Xcode tools."
end

exit "The frontmost document has been $locked."
You can run shell commands in a Perl block as shown above.

js
Posts: 229
Joined: 2007-04-12 14:59:36

Re: locking / unlocking the front file

Post by js » 2010-07-19 06:25:09

Thank you, Kino. For the moment I can't use your macro, though. I don't have the XCode tools anywhere near me. Are they an ultimate condition to lock a file out of Nisus?

Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: locking / unlocking the front file

Post by Kino » 2010-07-19 06:52:28

js wrote:I don't have the XCode tools anywhere near me.
Get a free ADC membership, then you can download the latest Xcode 3.2.2 for free.
Are they an ultimate condition to lock a file out of Nisus?
I don’t know. In your first posting, you mentioned “a shell file” (sic). If you have a shell script for locking/unlocking a file using other commands than SetFile and GetFileInfo, post it here.

User avatar
Hamid
Posts: 732
Joined: 2007-01-17 03:25:42

Re: locking / unlocking the front file

Post by Hamid » 2010-07-19 07:54:13

Xcode is on Snow Leopard install disk.

Post Reply