Deleting LiveJournal

About a year ago, I posted an article about the AppleScript I had written which, when run on a Mac computer in conjunction with the Safari web browser, would go through a LiveJournal account and save each entry to a PDF file, preserving the original formatting and comments.

Now I finally decided it’s time for me to delete my old journal. I was concerned, though, that purging the entire journal or marking all entries as deleted might just set a ‘deleted’ flag on them which could just as easily be un-set to bring everything back someday. So I decided to first set the text of each journal entry to the word “deleted” so as to make such a thing marginally more difficult.

Here’s the AppleScript that I came up with. It runs in Script Editor with Safari on macOS Big Sur. The buttons might be specific to my custom LiveJournal theme, so this script might not work for you as-is, but with some knowledge of CSS you can probably finagle it.

-- This script will delete LiveJournal pages, one by one.
-- Before it deletes each, it will change the text of that entry to the word "deleted",
-- as an extra safeguard against it ever being restored.

-- Start by going to your LiveJournal recent entries page

set editEntryButton to "document.querySelector('[title=\"Edit Entry\"]')"
set body to "document.querySelector('textarea#body')"
set saveEntryButton to "document.querySelector('[name=\"action:update\"]')"
set deleteEntryButton to "document.querySelector('[name=\"action:delete\"]')"

on wait()
	delay 3
end wait

on doJavaScript(js)
	tell application "Safari"
		ignoring application responses -- otherwise a JavaScript alert blocks AppleScript from continuing
			tell document 1 to do JavaScript js
		end ignoring
	end tell
end doJavaScript

-- wait for a specific page element to appear, as a way to make sure the page is loaded
on waitFor(element)
	tell application "Safari"
		tell document 1 to repeat
			delay 3
			do JavaScript element & " != null"
			if the result is true then exit repeat
		end repeat
	end tell
end waitFor

set done to false -- I never set it to true, but you could add a test for done-ness
repeat until done
	
	tell application "System Events"
		tell process "Safari"
			set frontmost to true
		end tell
	end tell
	
	-- set the text of the entry to "deleted"
	doJavaScript(editEntryButton & ".click()")
	waitFor(body)
	doJavaScript(body & ".value = 'deleted'")
	wait()
	doJavaScript(saveEntryButton & ".click()")
	
	-- then actually delete the entry
	waitFor(editEntryButton)
	doJavaScript(editEntryButton & ".click()")
	waitFor(deleteEntryButton)
	doJavaScript(deleteEntryButton & ".click()")
	
	-- press 'Return' to answer the 'really delete?' modal
	tell application "System Events"
		tell process "Safari"
			set frontmost to true
			delay 1
			keystroke return
		end tell
	end tell
	
	-- start over again with the next journal entry
	waitFor(editEntryButton)
	
end repeat

display notification "Finished deleting your LiveJournal."

Deleting LiveJournal Read More ยป