Notes app returns the ‘body’ property as html. I can’t remember how to change the html to plain text and rtf. Here’s a script for getting the body:
display dialog "Search:" default answer "word1 word2"
set user_text to text returned of result
set search_words to words of user_text
set found_notes to {}
tell application "Notes"
repeat with this_word in search_words
set temp_notes to (name of every note of folder "Scripts" whose body contains this_word)
repeat with this_note in temp_notes
if this_note is not in found_notes then
set end of found_notes to (contents of this_note)
end if
end repeat
end repeat
-- process found_notes
if found_notes is not {} then
set script_as_html to (body of note (item 1 of found_notes))
end if
-- etc.
end tell
The “Scripts” folder in my Notes app contains scripts and I’m trying to find a script that contains any word entered in the dialog.
I don’t think it was curl.
Edited: this is just a rough draft. Still thinking about it.
set htmlText to "<html><body>This is a text</body></html>"
set htmlSource to do shell script "echo " & quoted form of htmlText & " | textutil -stdin -stdout -format html -convert txt -encoding UTF-8"
One last question. If you wanted the output encoding to be rtf, then what would you use besides UTF-8 and how do you know what all the output encodings are?
These don’t look like parameters. I don’t know why they didn’t mention UTF-8 (maybe because it is the default). I’ll check out NSString Class Reference.
I see it now! And one other thing I found is that the parameters can be written in many ways. I tried it with lower case utf8 and it works according to the NSString Class Reference encodings.
I was wondering why your code was in that order. Now I understand.
set htmlText to "<html><body>This is a text</body></html>"
set htmlSource to do shell script "echo " & quoted form of htmlText & " | textutil -stdin -stdout -format html -convert rtf -encoding UTF-8"
Here’s the rough script (hardly any error checking) if anybody wants to use it.
display dialog "Search:" default answer "word1 word2"
set user_text to text returned of result
set search_words to words of user_text
set found_notes to {}
tell application "Notes"
repeat with this_word in search_words
set temp_notes to (name of every note of folder "Scripts" whose body contains this_word)
repeat with this_note in temp_notes
if this_note is not in found_notes then
set end of found_notes to (contents of this_note)
end if
end repeat
end repeat
-- process found_notes
if found_notes is not {} then
set script_html to (body of note (item 1 of found_notes))
set script_text to do shell script "echo " & quoted form of script_html & " | textutil -stdin -stdout -format html -convert txt -encoding utf8"
end if
end tell
Note that it only searches in a folder called “Scripts” in the Notes app and, as is, only reads the first note.