Using Applescript to replace negative indent in HTML
I am playing with a script to take HTML from this forum window and remove the negative indent that this page adds when you paste an applescript copied from the editor into it. I have sumitted feedback to apple and if anyone cares I encourage them to do so.
What I want to do:
Starting with the focus in this window,
click the HTML button
find/replace "text-indent: -" with "text-indent: "
paste back into this window
click the "show full editor" button
FYI- I do believe that applescript is probalbly not the best approach for this task but my true mission is to learn more about scripting and a small detour to a shell script hasn't seemed too far.
So far I have:
tell application "Safari"
activateapplication "Safari"
tell application "System Events" to keystroke "a" using command down
delay 0.15
tell application "System Events" to keystroke "c" using command down
end tell
activateapplication "TextEdit"
tell application "TextEdit"
makedocument
set text of front document to the clipboard
set fdText to "text-indent: -"
set rplText to "text-indent: "
activateapplication "TextEdit"
set the clipboard tofdText
tell application "System Events" to keystroke "f" using command down
tell application "System Events" to keystroke "v" using command down
delay 0.15
set the clipboard torplText
tell application "System Events" to keystroke "f" using [command down, option down]
tell application "System Events" to keystroke "v" using command down
delay 0.15
activateapplication "TextEdit"
tell application "System Events" to keystroke tab
delay 0.15
tell application "System Events" to keystroke space
delay 0.15
set sr to front document's text
set the clipboard tosr
end tell
activateapplication "Safari"
tell application "Safari"
tell application "System Events" to keystroke "v" using command down
end tell
This works for me as you see above but it is a bit of a kludge. Drew suggested in this thread here that I could do my find replace using a shell script and I am trying to implement that now.
set fdText to "text-indent: "
set rplText to "text-indent: "
set inputstring to the clipboard
-- use 'sed' to replace the '-' after the text-indent:
set cmd to "echo \"" & inputstring & "\" | sed -e 's/text-indent: /text-indent: /g' "
set outputstring to (do shell scriptcmd)
--see what we got
display dialog "inputstring: " & return & inputstring & return & return & "outputstring:" & return & outputstring
This script is stumbling when the clipboard has text with quotes in it. I have been copying this window after I click the HTML button.
My questions:
How do I get this shell script to work with the quotes?
How do I find and click the HTML button above and the "show full editor" button in the other window?
Thanks,
quinn
MacBook Pro, OS X Mavericks (10.9.5)