Due to the computer is sometimes slow to respond to UI cammands, the script below is failing in about 30% of the cases, pauses help (one pause has 3.5 seconds!!) but still problems sometimes. This macro (&AS script) will not be unfamiliar to some of our colleagues on this list.
What it does:
This macro lets the user copy the title of a webbtext (Serial Clipboard1) and (in this case) one more paragraph (Serial Clipboard2) from either Safari or Chrome and save it into a TextEdit* document with capture date/time and url, and to collect it to a folder (_INPUT).
(*for better styling, but TextWrangler would do if simpler.)
—————————————…————————————-
Serial AutoPaste TE 2C AS
The Hot Key ⌃7 is pressed
Execute AppleScript
set appPath to path to frontmost application as text
set AppleScript’s text item delimiters to {":", “.”}
set frontApp to text item -3 of appPath
if frontApp = “Safari” then
tell application "Safari"
set _url to URL of front document
end tell
else if frontApp = “Google Chrome” then
tell application "Google Chrome"
set _url to URL of active tab of front window
end tell
end if
– Just to demonstrate the value of variable _url.
– tell current application to display dialog _url
Save trimmed to variable ‘url’.
Activate TextEdit
Pause Until All Conditions Met
Condition iconApplication ‘TextEdit’ is at the front
Type the ⌘N Keystroke
Pause for 1.5 Seconds
Apply Style to Named Clipboard ‘Serial Clipboard1’
Set font to Lucida Grande.
Set size to 24.
Set foreground to Swatch
Paste from Named Clipboard ‘Serial Clipboard1’
Type the Return Keystroke
Insert Styled Text by Pasting
capt. %ShortDate% %ShortTime%
URL: %url%
Type the Return Keystroke
Type the Return Keystroke
Insert Styled Text by Pasting
Apply Style to Named Clipboard ‘Serial Clipboard2’
Set font to Lucida Grande.
Set size to 18.
Set foreground to Swatch
Paste from Named Clipboard ‘Serial Clipboard2’
Type the Return Keystroke
Insert Styled Text by Pasting
.-.
Execute AppleScript
tell application "TextEdit"
1st paragraph of text of first document
end tell
Save trimmed to variable ‘tettle’.
Speak Text With Voice ‘Veena’ at Default Rate
Title: %Variable%tettle%
Select Menu Item in TextEdit
Select: File ⇢ Save As…
Stop macro if menu cannot be selected.
Pause for 4 Seconds
Comment ‘added time’ from 1.5 to 2.5 sec to 4. sec
I found that Keyboard Maestro's ability to work with RTF is pretty good, so I abandoned the AppleScript elements for now.
The goal of this macro is to make a RTF clipping of the selection in Safari or Google Chrome in a specific directory: ~/Documents/_INPUT/
The file name follows the page title and uses a time-stamp to avoid naming collisions.
A header is added showing a time-stamp, the title, and the url of the page in question:
--------------------------------------------------
2015/40/14 11:40
how to show lines in common (reverse diff)? - Stack Overflow
http://stackoverflow.com/questions/746458/how-to-show-lines-in-common-reverse-diff
--------------------------------------------------
Formatting and URLs of the copied text are preserved.
Give it a try, and let me know what you think.
-Chris
Edit: 2015/05/16 16:23:
Fixed typo in ICU date format.
Added action to apply format to copied text (initially disabled).
With Safari update (around vs. 9 / OS El Capitan) for the macro to pick up the page title, it is necessary to check > Safari > Develop > ”Allow JavaScript for Apple Events.” Thanks to Chris S. for pointing this out!