Where are the Find/Replace saved expressions stored?
Two days ago I had to reinitialize my HD and reinstall everything from scratch. I had made a backup copy of my user folder, with documents and library, thinking this was enough to restore settings. It looks like, though, that the Find/Replace saved expressions are not saved along with Nisus' application support folder, nor its .plist file.
They were not many settings, only a dozen, as I rely mainly on macros, but there were some that were very useful to me.
Thanks, Henry.
Can't Find Saved Expressions.
Re: Can't Find Saved Expressions.
They are stored in com.nisus.NisusWriter.plist under 2:com.nisus.PowerFind.userExpressions as hexadecimal notation of RTF code. To restore the original styled text, something like this is necessary.Probably there would be a proper Unix command for this kind of conversion but I don't know.
Edit: The pref file is in binary format. To read it, you need Property List Editor or something alike. If the actual pref file contains your find expressions, you can use NW Pro's macro command Read User Default or /usr/bin/defaults.
Code: Select all
$data = '7b5c7274 6631205c 6d616320 5c616e73 69637067 31303030 30205c6e 69737573 76657273 696f6e33 30333030 205c6465 66663020 7b5c666f 6e747462 6c207b5c 6630205c 666e696c 205c6663 68617273 65743020 41476172 616d6f6e 6450726f 2d526567 756c6172 7b5c2a5c 66616c74 2041646f 62652047 6172616d 6f6e6420 50726f7d 3b7d7d7b 5c636f6c 6f727462 6c203b7d 7b5c2a5c 6e697375 73746f63 7461626c 65207d7b 5c2a5c6e 69737573 78657461 626c6520 7d7b5c73 74796c65 73686565 74207d5c 64656666 6f726d61 74205c66 65743220 5c66746e 626a205c 70617065 72773131 39303020 5c706170 65726831 36383430 205c6d61 72676c31 34343020 5c6d6172 67723134 3430205c 6d617267 74313830 30205c6d 61726762 31383030 205c6775 74746572 30205c70 676e7374 61727431 205c6e6f 636f6c62 616c205c 6630205c 73656374 64205c6c 696e656d 6f643020 5c636f6c 7331205c 6c747273 65637420 5c636f6c 62616c73 786e3020 5c706777 73786e31 31393030 205c7067 6873786e 31363834 30205c6d 6172676c 73786e31 34343020 5c6d6172 67727378 6e313434 30205c6d 61726774 73786e31 38303020 5c6d6172 67627378 6e313830 30205c67 75747465 7273786e 30205c68 65616465 72793732 30205c66 6f6f7465 72793732 30205c70 676e636f 6e74205c 70676e64 6563205c 73786e63 6f6e7420 5c73786e 64656320 7b5c6865 61646572 207d0a7b 5c666f6f 74657220 7d5c6465 66746162 37323020 5c706172 64205c71 6c205c77 69646374 6c706172 205c6e69 7375736b 65657030 205c6e69 7375736b 6565706e 30205c73 6230205c 73613020 5c736c32 3430205c 736c6d75 6c743120 5c6c7472 70617220 5c706172 6469726e 61747572 616c205c 6c693020 5c6c696e 30205c66 6930205c 72693020 5c72696e 30207b5c 6630205c 4170706c 65547970 65536572 76696365 7320283f 6929283f 3c3d5e7c 5c273563 74295c27 35636228 3f3a666f 72656163 687c7768 696c657c 69667c65 6c736966 7c656c73 657c656e 647c6272 65616b29 5c273563 627d7d'
$data.replaceAll '\G\x20?(\S{2})(?=\p{Any})', '\1\x20', 'E'
$data = $data.split "\x20"
$RTF = ''
foreach $datum in $data
$dec = Convert From Hex $datum
$RTF &= Text.newWithCharacter $dec
end
$exp = Decode RTF $RTF
Document.newWithText $exp
Edit: The pref file is in binary format. To read it, you need Property List Editor or something alike. If the actual pref file contains your find expressions, you can use NW Pro's macro command Read User Default or /usr/bin/defaults.
Re: Can't Find Saved Expressions.
Thank you, Kino. Unfortunately, substituting the old .plist for the new one doesn't restore the saved expressions. I was sure that they were there just before I reinstalled the OS, but I'm having second thoughts. No rocket science, though, luckily. I'll rewrite them when I need.
Greetings, Henry.
Greetings, Henry.
Re: Can't Find Saved Expressions.
Solved at last! I've found an old back-up copy of my home folder in a long-forgotten DVD.
Now, wouldn't it be good to save the expressions into Nisus application support folder? One may trash the .plist because of problems with the application, without knowing something like one's saved expressions are being jettisoned with the baby. I expected to only reset the preferences as they appear in the preferences panel. I didn't know I was trashing my saved expressions.
Greetings, Henry.
Now, wouldn't it be good to save the expressions into Nisus application support folder? One may trash the .plist because of problems with the application, without knowing something like one's saved expressions are being jettisoned with the baby. I expected to only reset the preferences as they appear in the preferences panel. I didn't know I was trashing my saved expressions.
Greetings, Henry.
Re: Can't Find Saved Expressions.
Glad to know you recovered your expressions successfully. I have Time Machine turned on but the worst occurs always “between”. The longest of my saved expression consists of 45,000 characters (for detecting characters not in JIS X 0208, obsolete Japanese character set). It was generated by a macro I don’t have any more and and I won’t dare to do it again.
Anyway, perhaps this may help… next time ;-)
And… er… feature requests!
• Export Saved Expressions in a human readable format.
• Import Saved Expressions, ideally with a dialog box allowing you to import them selectively.
Thanks.
Anyway, perhaps this may help… next time ;-)
Code: Select all
### Export Saved Expressions ###
# Export Saved Expressions as a new document.
Require Pro Version 1.3
Debug.setCodeProfilingEnabled false
$data = Read User Default '2:com.nisus.PowerFind.userExpressions'
if $data == undefined
exit 'Cannot read Saved Expressions, exit...'
end
$nameSels = $data.findAll '(?<=\sname\x20=\x20"|\sname\x20=\x20)[^"].*?(?="?;$)', 'E'
$expSels = $data.findAll '(?<=expression\x20=\x20<)([\h\x20]+)(?=>;)', 'E'
$names = $expressions = Array.new
$delRange = Range.new 0, 2
foreach $sel in $nameSels
$name = $sel.substring
$founds = $name.findAll '\x{5C}U\h{4}', 'E'
if $founds.count
foreach $found in reversed $founds
$hex = $found.substring
$hex.deleteInRange $delRange
$d = Convert From Hex $hex
$char = Text.newWithCharacter $d
$name.replaceInRange $found.range, $char
end
end
$names.appendValue $name
end
foreach $sel in $expSels
$expressions.appendValue $sel.substring
end
$savedExpressions = Hash.new
Set Exported Perl Variables 'names', 'expressions', 'savedExpressions'
begin Perl
foreach my $name (@names) {
my $exp = shift @expressions;
$exp =~ tr/\x20//d;
$exp =~ s/(\S\S)/chr(hex($1))/geo;
$savedExpressions{$name} = $exp;
}
end
$output = ''
$names = $savedExpressions.keys
$names.sort 'li'
$LF = Cast to String "\n"
foreach $name in $names
$output &= Cast to Attributed String $name
$output &= $LF
$output &= Decode RTF $savedExpressions{$name}
$output &= $LF & $LF
end
$output.findAndReplace '\n\z', '', 'E'
Document.newWithText $output
Select Document Start
### end of macro ###
• Export Saved Expressions in a human readable format.
• Import Saved Expressions, ideally with a dialog box allowing you to import them selectively.
Thanks.
Last edited by Kino on 2009-07-08 06:14:09, edited 1 time in total.
Re: Can't Find Saved Expressions.
Well, you're great, Kino. Thank you.
Greetings, Henry.
That's exactly what I was going to ask. It was just a matter of time-zone.Kino wrote: • Export Saved Expressions in a human readable format.
• Import Saved Expressions, ideally with a dialog box allowing you to import them selectively.
Greetings, Henry.
AppleScript
Kino-san, this might be a good excuse for you to experiment with AppleScript. The System Events application includes a "property list suite" that allows you to directly read and modify property list items without the need to parse the hexadecimal data.
I've never used the "property list suite", so I probably cannot answer any more specific questions.
I've never used the "property list suite", so I probably cannot answer any more specific questions.
Re: AppleScript
Thank you for the suggestion. I did not know Property List Suite. Perhaps and hopefully it will return “字” instead of “\U5b57” for the name field but I don’t think it will give us a plain RTF code in the expression field. If I’m not mistaken, values in that field are encoded as such from the beginning.
And what is nice with Read User Default command is that it returns the current value of a default key (“2:com.nisus.PowerFind.userExpressions” in this cas). Usually we use /usr/bin/defaults to read or write a preferences file (com.nisus.NisusWriter.plist) but changes are not always written to the file immediately. So we can never know if values in the file are up-to-date except when the application is not running ;-) Property List Suite is in the same situation because it cannot access NW Pro’s internal data.
--
I edited the macro above so that it exits if “2:com.nisus.PowerFind.userExpressions” does not exist, i.e. if there is no Saved Expression.
And I forgot to say this: the reason why I did not use Perl to convert hexadecimal notations of the type “\U5b57” in the name field is that my Perl code similar to that for the expression field did not work for surrogate pairs (U+10000 and higher). Probably there would be a proper (and simple?) perlish way to do it but I don’t know.
And what is nice with Read User Default command is that it returns the current value of a default key (“2:com.nisus.PowerFind.userExpressions” in this cas). Usually we use /usr/bin/defaults to read or write a preferences file (com.nisus.NisusWriter.plist) but changes are not always written to the file immediately. So we can never know if values in the file are up-to-date except when the application is not running ;-) Property List Suite is in the same situation because it cannot access NW Pro’s internal data.
--
I edited the macro above so that it exits if “2:com.nisus.PowerFind.userExpressions” does not exist, i.e. if there is no Saved Expression.
And I forgot to say this: the reason why I did not use Perl to convert hexadecimal notations of the type “\U5b57” in the name field is that my Perl code similar to that for the expression field did not work for surrogate pairs (U+10000 and higher). Probably there would be a proper (and simple?) perlish way to do it but I don’t know.
Re: Can't Find Saved Expressions.
I assume you recognize that the "delay" problem with "/usr/bin/defaults" and Property List Suite is irrelevant to the present situation in which you are merely reading the preferences rather than modifying them.Kino wrote:
what is nice with Read User Default command is that it returns the current value of a default key (“2:com.nisus.PowerFind.userExpressions” in this cas). Usually we use /usr/bin/defaults to read or write a preferences file (com.nisus.NisusWriter.plist) but changes are not always written to the file immediately. So we can never know if values in the file are up-to-date except when the application is not running ;-) Property List Suite is in the same situation because it cannot access NW Pro’s internal data.
In situations in which you *do* want to modify the preferences, the problem is even more severe than a delay in writing to the file. The real problem is whether NWP will read the changes to the file! For example, it appears that NWP reads the DraftView.zoom preference only when NWP launches, so directly changing its value in the preference file accomplishes nothing until NWP is re-launched. That's why I resorted to a GUI script to modify this setting.
- martin
- Official Nisus Person
- Posts: 5230
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: Can't Find Saved Expressions.
Unfortunately no, the delay can affect both reads and writes. Consider, if the user adds a new saved find expression, that expression may not yet have been written to the file when you run the macro.Bob Stern wrote:I assume you recognize that the "delay" problem with "/usr/bin/defaults" and Property List Suite is irrelevant to the present situation in which you are merely reading the preferences rather than modifying them.
When writes occur I couldn't tell you exactly, since that system is managed by Apple. Likely it batches updates and saves them after some preset time period has elapsed, or the application has gone idle.