User:Orange Suede Sofa/Archiving with AppleScript
Appearance
Has this ever happened to you?
[edit]You tried to verify a reference, but the URL was dead. You went to the Wayback Machine and found a URL, but are too lazy pressed for time to update the citation template to include the archived URL. And finally, you edit Wikipedia with macOS.
How this works
[edit]- Find your archived URL and copy it to your clipboard. This script only works with Wayback Machine URLs. If you don't have an archive URL ready, then learn more at WP:LINKROT.
- Edit your page and find the citation that needs to be updated.
- Place your insertion cursor before the last
}}
in the citation. - Run the script in the manner of your choosing (I use Automator, which will need to have Accessibility permissions turned on in Settings→Privacy & Security).
The script will insert |archive-url=
with the URL from the clipboard and parse the URL to insert the |archive-date=
parameter. The script does not add |url-status=dead
, as this is implied if |archive-url=
is present.[1]
Example
[edit]Old citation
[edit]{{cite news|url=https://www.newsday.com/sports/baseball/baseball-hall-of-fame-chipper-jones-jim-thome-1.16334426|title=Jones, Thome, Guerrero, Hoffman elected to HOF|newspaper=Newsday|access-date=January 28, 2018}}
Contents of your clipboard
[edit]Script output
[edit]|archive-url=http://web.archive.org/web/20180714082013/https://www.newsday.com/sports/baseball/baseball-hall-of-fame-chipper-jones-jim-thome-1.16334426|archive-date=2018-07-14
New citation
[edit]{{cite news|url=https://www.newsday.com/sports/baseball/baseball-hall-of-fame-chipper-jones-jim-thome-1.16334426|title=Jones, Thome, Guerrero, Hoffman elected to HOF|newspaper=Newsday|access-date=January 28, 2018|archive-url=http://web.archive.org/web/20180714082013/https://www.newsday.com/sports/baseball/baseball-hall-of-fame-chipper-jones-jim-thome-1.16334426|archive-date=2018-07-14}}
Code
[edit]on run {input, parameters}
# parse archive date from Wayback Machine URL. Example: http://web.archive.org/web/20180714082013/https://w
set myURL to (the clipboard as text)
set text item delimiters to {"/"}
set myRaw to text item 5 of myURL
set myArchiveDate to text 1 thru 4 of myRaw & "-" & text 5 thru 6 of myRaw & "-" & text 7 thru 8 of myRaw
# build new string
set myInsertion to "|archive-url=" & (the clipboard as text) & "|archive-date=" & myArchiveDate
tell application "System Events"
keystroke myInsertion
end tell
return input
end run