Skip to content

Instantly share code, notes, and snippets.

@robjwells
Last active April 28, 2021 03:00

Revisions

  1. robjwells revised this gist Mar 20, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion CopyCleaner.applescript
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,7 @@ on open theStories

    -- Break byline after name and ensure lower-case 'b'
    -- Check for (rare) 3-word bylines, else handle 2-word bylines
    my grepRep("^(by Our (?:Foreign|News|Sport) Desk|by Morning Star Reporter)(?:[ ,]*)(.*)\\r+", "\\l\\1\\r\\2\\r")
    my grepRep("^(by Our (?:Foreign|News|Sports) Desk|by Morning Star Reporter)(?:[ ,]*)(.*)\\r+", "\\l\\1\\r\\2\\r")
    if the result is 0 then -- 3-word byline not found
    -- Break two-word byline
    my grepRep("^(by [-[:alpha:]]+ [-[:alpha:]]+)(?:[ ,]*)(.*)\\r+", "\\l\\1\\r\\2\\r")
  2. robjwells revised this gist Dec 12, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion CopyCleaner.applescript
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@ on open theStories

    my grepRep(" [–-] ", "") -- En-dashes & hyphens to em-dashes
    my grepRep("^• *|^n ", "n") -- Blob-pars (nHeady heady)
    my grepRep("([.0-9]*) *(%|percent)", "\\1 per cent") -- "per cent"
    my grepRep("([.0-9]*) *(%|percent)(?!age)", "\\1 per cent") -- "per cent"
    my litRep("...", "") -- Ellipses

    -- Break byline after name and ensure lower-case 'b'
  3. robjwells revised this gist Dec 5, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion CopyCleaner.applescript
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,7 @@ on open theStories

    -- Break byline after name and ensure lower-case 'b'
    -- Check for (rare) 3-word bylines, else handle 2-word bylines
    my grepRep("^(by Our (?:Foreign|News) Desk|by Morning Star Reporter)(?:[ ,]*)(.*)\\r+", "\\l\\1\\r\\2\\r")
    my grepRep("^(by Our (?:Foreign|News|Sport) Desk|by Morning Star Reporter)(?:[ ,]*)(.*)\\r+", "\\l\\1\\r\\2\\r")
    if the result is 0 then -- 3-word byline not found
    -- Break two-word byline
    my grepRep("^(by [-[:alpha:]]+ [-[:alpha:]]+)(?:[ ,]*)(.*)\\r+", "\\l\\1\\r\\2\\r")
  4. robjwells revised this gist Sep 4, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions CopyCleaner.applescript
    Original file line number Diff line number Diff line change
    @@ -30,10 +30,10 @@ on open theStories

    -- Break byline after name and ensure lower-case 'b'
    -- Check for (rare) 3-word bylines, else handle 2-word bylines
    my grepRep("^(by Our (?:Foreign|News) Desk|by Morning Star Reporter)(?:[ ,]*)(.*)\\r{2,}", "\\l\\1\\r\\2\\r")
    my grepRep("^(by Our (?:Foreign|News) Desk|by Morning Star Reporter)(?:[ ,]*)(.*)\\r+", "\\l\\1\\r\\2\\r")
    if the result is 0 then -- 3-word byline not found
    -- Break two-word byline
    my grepRep("^(by [-[:alpha:]]+ [-[:alpha:]]+)(?:[ ,]*)(.*)\\r{2,}", "\\l\\1\\r\\2\\r")
    my grepRep("^(by [-[:alpha:]]+ [-[:alpha:]]+)(?:[ ,]*)(.*)\\r+", "\\l\\1\\r\\2\\r")
    end if

    my grepRep("\\r+\\z", "") -- Delete empty lines at end
  5. robjwells revised this gist Sep 4, 2013. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions CopyCleaner.applescript
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,8 @@ on open theStories
    repeat with aStory in theStories
    tell application "TextWrangler"
    open aStory
    tell text 1 of text window 1
    tell the front text document
    set encoding to "Unicode (UTF-8)"

    educate quotes with replacing target

    @@ -29,10 +30,10 @@ on open theStories

    -- Break byline after name and ensure lower-case 'b'
    -- Check for (rare) 3-word bylines, else handle 2-word bylines
    my grepRep("^(by Our (?:Foreign|News) Desk|by Morning Star Reporter)(?:[ ,]*)(.*)\\r+", "\\l\\1\\r\\2\\r")
    my grepRep("^(by Our (?:Foreign|News) Desk|by Morning Star Reporter)(?:[ ,]*)(.*)\\r{2,}", "\\l\\1\\r\\2\\r")
    if the result is 0 then -- 3-word byline not found
    -- Break two-word byline
    my grepRep("^(by [-[:alpha:]]+ [-[:alpha:]]+)(?:[ ,]*)(.*)\\r+", "\\l\\1\\r\\2\\r")
    my grepRep("^(by [-[:alpha:]]+ [-[:alpha:]]+)(?:[ ,]*)(.*)\\r{2,}", "\\l\\1\\r\\2\\r")
    end if

    my grepRep("\\r+\\z", "") -- Delete empty lines at end
  6. Rob Wells revised this gist Jun 15, 2013. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions CopyCleaner.applescript
    Original file line number Diff line number Diff line change
    @@ -29,11 +29,11 @@ on open theStories

    -- Break byline after name and ensure lower-case 'b'
    -- Check for (rare) 3-word bylines, else handle 2-word bylines
    my grepRep("^(by Our (?:Foreign|News) Desk|by Morning Star Reporter)(?:[ ,]*)(.*)\\r+", "\\l\\1\\r\\2\\r")
    if the result is 0 then -- 3-word byline not found
    -- Break two-word byline
    my grepRep("^(by [-[:alpha:]]+ [-[:alpha:]]+)(?:[ ,]*)(.*)\\r+", "\\l\\1\\r\\2\\r")
    end if
    my grepRep("^(by Our (?:Foreign|News) Desk|by Morning Star Reporter)(?:[ ,]*)(.*)\\r+", "\\l\\1\\r\\2\\r")
    if the result is 0 then -- 3-word byline not found
    -- Break two-word byline
    my grepRep("^(by [-[:alpha:]]+ [-[:alpha:]]+)(?:[ ,]*)(.*)\\r+", "\\l\\1\\r\\2\\r")
    end if

    my grepRep("\\r+\\z", "") -- Delete empty lines at end
    my grepRep("”([[:punct:]])", "\\1”") -- Transpose rdquo with punctuation.
  7. Rob Wells revised this gist Jun 15, 2013. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions CopyCleaner.applescript
    Original file line number Diff line number Diff line change
    @@ -29,11 +29,11 @@ on open theStories

    -- Break byline after name and ensure lower-case 'b'
    -- Check for (rare) 3-word bylines, else handle 2-word bylines
    my grepRep("^(by Our (?:Foreign|News) Desk|by Morning Star Reporter)(?:[ ,]*)(.*)\\r{2,}", "\\l\\1\\r\\2\\r")
    if the result is 0 then -- 3-word byline not found
    -- Break two-word byline
    my grepRep("^(by [-[:alpha:]]+ [-[:alpha:]]+)(?:[ ,]*)(.*)\\r{2,}", "\\l\\1\\r\\2\\r")
    end if
    my grepRep("^(by Our (?:Foreign|News) Desk|by Morning Star Reporter)(?:[ ,]*)(.*)\\r+", "\\l\\1\\r\\2\\r")
    if the result is 0 then -- 3-word byline not found
    -- Break two-word byline
    my grepRep("^(by [-[:alpha:]]+ [-[:alpha:]]+)(?:[ ,]*)(.*)\\r+", "\\l\\1\\r\\2\\r")
    end if

    my grepRep("\\r+\\z", "") -- Delete empty lines at end
    my grepRep("”([[:punct:]])", "\\1”") -- Transpose rdquo with punctuation.
  8. Rob Wells revised this gist May 6, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions CopyCleaner.applescript
    Original file line number Diff line number Diff line change
    @@ -29,10 +29,10 @@ on open theStories

    -- Break byline after name and ensure lower-case 'b'
    -- Check for (rare) 3-word bylines, else handle 2-word bylines
    my grepRep("^(by Our (?:Foreign|News) Desk|by Morning Star Reporter) *(.*)\\r{2,}", "\\l\\1\\r\\2\\r")
    my grepRep("^(by Our (?:Foreign|News) Desk|by Morning Star Reporter)(?:[ ,]*)(.*)\\r{2,}", "\\l\\1\\r\\2\\r")
    if the result is 0 then -- 3-word byline not found
    -- Break two-word byline
    my grepRep("^(by [-[:alpha:]]+ [-[:alpha:]]+) *(.*)\\r{2,}", "\\l\\1\\r\\2\\r")
    my grepRep("^(by [-[:alpha:]]+ [-[:alpha:]]+)(?:[ ,]*)(.*)\\r{2,}", "\\l\\1\\r\\2\\r")
    end if

    my grepRep("\\r+\\z", "") -- Delete empty lines at end
  9. Rob Wells revised this gist May 3, 2013. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions CopyCleaner.applescript
    Original file line number Diff line number Diff line change
    @@ -29,11 +29,11 @@ on open theStories

    -- Break byline after name and ensure lower-case 'b'
    -- Check for (rare) 3-word bylines, else handle 2-word bylines
    my grepRep("^(by Our (?:Foreign|News) Desk|by Morning Star Reporter) *(.*)\\r{2,}", "\\l\\1\\r\\2\\r")
    if the result is 0 then -- 3-word byline not found
    -- Break two-word byline
    my grepRep("^(by [-[:alpha:]]+ [-[:alpha:]]+) *(.*)\\r{2,}", "\\l\\1\\r\\2\\r")
    end if
    my grepRep("^(by Our (?:Foreign|News) Desk|by Morning Star Reporter) *(.*)\\r{2,}", "\\l\\1\\r\\2\\r")
    if the result is 0 then -- 3-word byline not found
    -- Break two-word byline
    my grepRep("^(by [-[:alpha:]]+ [-[:alpha:]]+) *(.*)\\r{2,}", "\\l\\1\\r\\2\\r")
    end if

    my grepRep("\\r+\\z", "") -- Delete empty lines at end
    my grepRep("”([[:punct:]])", "\\1”") -- Transpose rdquo with punctuation.
  10. Rob Wells revised this gist May 3, 2013. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions CopyCleaner.applescript
    Original file line number Diff line number Diff line change
    @@ -29,11 +29,11 @@ on open theStories

    -- Break byline after name and ensure lower-case 'b'
    -- Check for (rare) 3-word bylines, else handle 2-word bylines
    my grepRep("^(by Our (?:Foreign|News) Desk|by Morning Star Reporter) *(.*)", "\\l\\1\\r\\2")
    if the result is 0 then -- 3-word byline not found
    -- Break two-word byline
    my grepRep("^(by [-[:alpha:]]+ [-[:alpha:]]+) *(.*)", "\\l\\1\\r\\2")
    end if
    my grepRep("^(by Our (?:Foreign|News) Desk|by Morning Star Reporter) *(.*)\\r{2,}", "\\l\\1\\r\\2\\r")
    if the result is 0 then -- 3-word byline not found
    -- Break two-word byline
    my grepRep("^(by [-[:alpha:]]+ [-[:alpha:]]+) *(.*)\\r{2,}", "\\l\\1\\r\\2\\r")
    end if

    my grepRep("\\r+\\z", "") -- Delete empty lines at end
    my grepRep("”([[:punct:]])", "\\1”") -- Transpose rdquo with punctuation.
  11. Rob Wells revised this gist Mar 12, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions CopyCleaner.applescript
    Original file line number Diff line number Diff line change
    @@ -29,10 +29,10 @@ on open theStories

    -- Break byline after name and ensure lower-case 'b'
    -- Check for (rare) 3-word bylines, else handle 2-word bylines
    my grepRep("^(by Our (?:Foreign|News) Desk|by Morning Star Reporter) (.+)", "\\l\\1\\r\\2")
    my grepRep("^(by Our (?:Foreign|News) Desk|by Morning Star Reporter) *(.*)", "\\l\\1\\r\\2")
    if the result is 0 then -- 3-word byline not found
    -- Break two-word byline
    my grepRep("^(by [-[:alpha:]]+ [-[:alpha:]]+) (.+)", "\\l\\1\\r\\2")
    my grepRep("^(by [-[:alpha:]]+ [-[:alpha:]]+) *(.*)", "\\l\\1\\r\\2")
    end if

    my grepRep("\\r+\\z", "") -- Delete empty lines at end
  12. Rob Wells revised this gist Mar 3, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions CopyCleaner.applescript
    Original file line number Diff line number Diff line change
    @@ -31,8 +31,8 @@ on open theStories
    -- Check for (rare) 3-word bylines, else handle 2-word bylines
    my grepRep("^(by Our (?:Foreign|News) Desk|by Morning Star Reporter) (.+)", "\\l\\1\\r\\2")
    if the result is 0 then -- 3-word byline not found
    -- Break byline with title/location
    my grepRep("^(by [-a-z]+ [-a-z]+) (.+)", "\\l\\1\\r\\2")
    -- Break two-word byline
    my grepRep("^(by [-[:alpha:]]+ [-[:alpha:]]+) (.+)", "\\l\\1\\r\\2")
    end if

    my grepRep("\\r+\\z", "") -- Delete empty lines at end
  13. Rob Wells revised this gist Feb 25, 2013. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions CopyCleaner.applescript
    Original file line number Diff line number Diff line change
    @@ -32,9 +32,8 @@ on open theStories
    my grepRep("^(by Our (?:Foreign|News) Desk|by Morning Star Reporter) (.+)", "\\l\\1\\r\\2")
    if the result is 0 then -- 3-word byline not found
    -- Break byline with title/location
    my grepRep("^(by [-a-z]+ [-a-z]+) (.+)", "\\1\\r\\2")
    my grepRep("^(by [-a-z]+ [-a-z]+) (.+)", "\\l\\1\\r\\2")
    end if
    my grepRep("^(by ([-a-z]+)+\\r)", "\\l\\1") -- Makes sure "by" is lowercase

    my grepRep("\\r+\\z", "") -- Delete empty lines at end
    my grepRep("”([[:punct:]])", "\\1”") -- Transpose rdquo with punctuation.
  14. Rob Wells revised this gist Feb 25, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion CopyCleaner.applescript
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ on open theStories
    educate quotes with replacing target

    -- Remove hard-wraps (not perfect)
    my grepRep("([-,—:;[:alnum:]) *\\r *([-,—:;[:alnum:]])", "\\1 \\2")
    my grepRep("([-,—:;[:alnum:]]) *\\r *([-,—:;[:alnum:]])", "\\1 \\2")
    -- Important thing to note is that it only finds non-terminal punctuation.
    -- It hits properly formatted bylines, but the byline replace fixes it later.

  15. Rob Wells revised this gist Feb 25, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion CopyCleaner.applescript
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ on open theStories
    educate quotes with replacing target

    -- Remove hard-wraps (not perfect)
    my grepRep("([-,—:;a-zA-Z0-9]) *\\r *([-,—:;a-zA-Z0-9])", "\\1 \\2")
    my grepRep("([-,—:;[:alnum:]) *\\r *([-,—:;[:alnum:]])", "\\1 \\2")
    -- Important thing to note is that it only finds non-terminal punctuation.
    -- It hits properly formatted bylines, but the byline replace fixes it later.

  16. Rob Wells revised this gist Feb 25, 2013. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions CopyCleaner.applescript
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ on open theStories
    my grepRep("^ ", "") -- Remove spaces at the start of lines
    my grepRep("\\t+", "") -- Remove tabs

    -- Super-script numbers to quote marks
    -- Superscript numbers to quote marks
    my litRep("¹", "") -- Apostrophe
    my litRep("²", "") -- Right double
    my litRep("³", "") -- Left double
    @@ -28,10 +28,11 @@ on open theStories
    my litRep("...", "") -- Ellipses

    -- Break byline after name and ensure lower-case 'b'
    -- Initial check is for 3-word bylines, regular (2-word) bylines handled in the if block
    -- Check for (rare) 3-word bylines, else handle 2-word bylines
    my grepRep("^(by Our (?:Foreign|News) Desk|by Morning Star Reporter) (.+)", "\\l\\1\\r\\2")
    if the result is 0 then -- 3-word byline not found
    my grepRep("^(by [-a-z]+ [-a-z]+) (.+)", "\\1\\r\\2") -- Break byline with title/location
    -- Break byline with title/location
    my grepRep("^(by [-a-z]+ [-a-z]+) (.+)", "\\1\\r\\2")
    end if
    my grepRep("^(by ([-a-z]+)+\\r)", "\\l\\1") -- Makes sure "by" is lowercase

  17. Rob Wells revised this gist Feb 25, 2013. No changes.
  18. Rob Wells created this gist Feb 25, 2013.
    63 changes: 63 additions & 0 deletions CopyCleaner.applescript
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,63 @@
    -- By Rob Wells for the Morning Star

    on open theStories
    repeat with aStory in theStories
    tell application "TextWrangler"
    open aStory
    tell text 1 of text window 1

    educate quotes with replacing target

    -- Remove hard-wraps (not perfect)
    my grepRep("([-,—:;a-zA-Z0-9]) *\\r *([-,—:;a-zA-Z0-9])", "\\1 \\2")
    -- Important thing to note is that it only finds non-terminal punctuation.
    -- It hits properly formatted bylines, but the byline replace fixes it later.

    my grepRep(" {2,}", " ") -- Multiple spaces to single space
    my grepRep("^ ", "") -- Remove spaces at the start of lines
    my grepRep("\\t+", "") -- Remove tabs

    -- Super-script numbers to quote marks
    my litRep("¹", "") -- Apostrophe
    my litRep("²", "") -- Right double
    my litRep("³", "") -- Left double

    my grepRep(" [–-] ", "") -- En-dashes & hyphens to em-dashes
    my grepRep("^• *|^n ", "n") -- Blob-pars (nHeady heady)
    my grepRep("([.0-9]*) *(%|percent)", "\\1 per cent") -- "per cent"
    my litRep("...", "") -- Ellipses

    -- Break byline after name and ensure lower-case 'b'
    -- Initial check is for 3-word bylines, regular (2-word) bylines handled in the if block
    my grepRep("^(by Our (?:Foreign|News) Desk|by Morning Star Reporter) (.+)", "\\l\\1\\r\\2")
    if the result is 0 then -- 3-word byline not found
    my grepRep("^(by [-a-z]+ [-a-z]+) (.+)", "\\1\\r\\2") -- Break byline with title/location
    end if
    my grepRep("^(by ([-a-z]+)+\\r)", "\\l\\1") -- Makes sure "by" is lowercase

    my grepRep("\\r+\\z", "") -- Delete empty lines at end
    my grepRep("”([[:punct:]])", "\\1”") -- Transpose rdquo with punctuation.

    end tell
    end tell
    end repeat
    end open


    -- Convenience wrapper functions

    on litRep(searchString, replaceString) -- Literal search and replace
    tell application "TextWrangler"
    tell text 1 of text window 1
    replace searchString using replaceString options {search mode:literal, starting at top:true}
    end tell
    end tell
    end litRep

    on grepRep(searchString, replaceString) -- Grep search and replace
    tell application "TextWrangler"
    tell text 1 of text window 1
    replace searchString using replaceString options {search mode:grep, starting at top:true}
    end tell
    end tell
    end grepRep