Change identical style in several files

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

Re: Change identical style in several files

Post by js »

Thanks again to all who have been helping. Combining elements of what I learned I found that a single import can be done comfortably like this:

Code: Select all

$doc = Document.active
# choosing the style set from Style Library:
$folderPath = '/Applications/nisus writer settings/Style Library/'
File.requireAccessAtPath($folderPath) # exclude sandboxing
$files = File.namesInFolderAtPath $folderPath
$fileName = Prompt Options 'Select a file...', "from files under $folderPath", 'Open', $files
# applying the style set to the active document:
$styleDoc = Document.withDisplayName $fileName
$doc.addStyles $styleDoc.allStyles, "replace"
For importing same styles on many files it's probably easiest to manually choose the styles file and use only

Code: Select all

$doc = Document.active
$styleDoc = Document.withDisplayName $fileName
$doc.addStyles $styleDoc.allStyles, "replace"
js
Posts: 251
Joined: 2007-04-12 14:59:36

Re: Change identical style in several files

Post by js »

For a single import, I tried to profit from everybodys help and suggestions to end with a handy macro like this. It lets the user choose from the style library and provides for sandboxing. Thank you all.

Code: Select all

$doc = Document.active 
   # choosing the style set from Style Library:
$folderPath = '/Applications/nisus writer settings/Style Library/'
File.requireAccessAtPath($folderPath) # exclude sandboxing
$files = File.namesInFolderAtPath $folderPath
$fileName = Prompt Options 'Select a file...', "from files under $folderPath", 'Open', $files
   # applying the style set to the active document:
$styleFilePath = "/Applications/nisus writer settings/Style Library/$fileName"
$styleDoc = Document.open $styleFilePath, @false
$doc.addStyles $styleDoc.allStyles, "replace"
$styleDoc.close
Post Reply