NISUS Archives

February 2013

NISUS@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Þorvarður Davíðsson <[log in to unmask]>
Reply To:
Date:
Wed, 13 Feb 2013 03:49:30 +0100
Content-Type:
text/plain
Parts/Attachments:
text/plain (65 lines)
The following macro opens ALL chosen documents and concatenates them in an untitled document. It is a nuisance having to close all the documents again, especially if a large number of documents has been opened. 

I haven’t be able to figure out how to change this macro so that only the new concatenated document will stay open. I would also like the macro to suggest the name "Concatenated file" for the new file, so that I would just have to click an OK button to accept the name.
 
Can anyone help?
Þorvarður


# Create a new document by joining all documents in a chosen folder.
# This macro appends a page break between each file not already ending in a break.
#
# This macro was originally written by Kino, whose other macros can
# be found at http://www2.odn.ne.jp/alt-quinon/files/NWPro/

$separator = Cast to String "\x0C"  # Page/Section Break

Require Pro Version 1.3
Debug.setCodeProfilingEnabled false

$files = Choose Files '~/Documents', 'Choose Files to Join'
if $files == undefined
	exit
end
if $files.count == 1
	exit 'You must select more than a single file to join, aborting.'
end

$fileNames = Array.new
foreach $file in $files
	$fileNames.appendValue $file.lastFilePathComponent
end

$fileNames = $fileNames.join "\n"
Prompt 'Files will be joined in the following order:', $fileNames, 'OK'

$newText = $docs = Array.new
$last = $files.count - 1
foreach $i, $file in $files
	$doc = Document.open $file, false
	$text = $doc.text
	$newText.appendValue $text
	$docs.appendValue $doc
	if $i != $last
		$range = Range.new $text.length - $separator.length, $separator.length
		$lastChar = $text.substringInRange $range
		if $lastChar != $separator
			$newText.appendValue $separator
		end
	else
		$range = Range.new $text.length - 1, 1
		$lastChar = $text.substringInRange $range
		$LF = Cast to String "\n"
		if $lastChar == $LF
			$newText.appendValue $LF
		end
	end
end

$newText = $newText.join ''
Document.newWithText $newText

foreach $doc in $docs
	$doc.close true
end

ATOM RSS1 RSS2