Skip to content

Instantly share code, notes, and snippets.

@NSBum
Created February 23, 2017 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NSBum/b29064cf63c4bd9f0d29697f3bfdeeab to your computer and use it in GitHub Desktop.
Save NSBum/b29064cf63c4bd9f0d29697f3bfdeeab to your computer and use it in GitHub Desktop.
--
-- Created by: Alan Duncan
-- Created on: 2017-01-11
--
-- Copyright (c) 2017 OjisanSeiuchi
-- All Rights Reserved
--
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
set logPath to "/Users/alan/Documents/dev/scripts+tools/AppleScript logs/anki-reword-gender-log.txt"
set commonScript to load script alias ((path to library folder from user domain as string) ¬
& "Scripts:commonLog.scpt")
set {originalDelimiters, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {", "}}
set notes to the clipboard
set wordItems to text items of notes
my replace_matches(wordItems, "female", "feminine", false)
my replace_matches(wordItems, "male", "masculine", false)
set modifiedText to wordItems as text
delay 0.75
tell application "Anki"
activate
end tell
my openHTMLDialog()
set pasteText to "<ul>
<li>" & modifiedText & "</li>
</ul>"
set the clipboard to {text:(pasteText as string), Unicode text:pasteText}
tell application "System Events"
keystroke "v" using command down
end tell
delay 0.5
my closeHTMLDialog()
set AppleScript's text item delimiters to originalDelimiters
on replace_matches(this_list, match_item, replacement_item, replace_all)
repeat with i from 1 to the count of this_list
set this_item to item i of this_list
if this_item is the match_item then
set item i of this_list to the replacement_item
if replace_all is false then return this_list
end if
end repeat
return this_list
end replace_matches
on openHTMLDialog()
tell application "System Events"
keystroke "x" using {shift down, command down}
delay 0.5
end tell
end openHTMLDialog
on closeHTMLDialog()
try
tell application "System Events"
tell process "Anki"
click button 1 of window "HTML Editor"
end tell
end tell
on error errStr number errorNumber
# echo to file
set myObj to "error"
log_event((errStr as string), logPath) of commonScript
end try
end closeHTMLDialog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment