Browse Source

add the scripts

Andrew 3 months ago
commit
a700cfc910

+ 16 - 0
automating-password-v2.txt

@@ -0,0 +1,16 @@
+-- Taken from a comment by Mr. X on http://selfsuperinit.com/2014/01/20/exporting-icloud-keychain-passwords-as-a-plain-text-file/
+set keychainPassword to "secret"
+
+tell application "System Events"
+	repeat while exists (processes where name is "SecurityAgent")
+		tell process "SecurityAgent"
+			try -- added
+				set value of text field 1 of window 1 to keychainPassword
+				click button "OK" of window 1
+			on error -- added
+				-- do nothing and skip -- added
+			end try -- added
+		end tell
+		delay 0.2
+	end repeat
+end tell

+ 12 - 0
automating-password.txt

@@ -0,0 +1,12 @@
+-- Taken from a comment by Mr. X on http://selfsuperinit.com/2014/01/20/exporting-icloud-keychain-passwords-as-a-plain-text-file/
+set keychainPassword to "keychain password"
+
+tell application "System Events"
+    repeat while exists (processes where name is "SecurityAgent")
+        tell process "SecurityAgent"
+            set value of text field 1 of window 1 to keychainPassword
+            click button "OK" of window 1
+        end tell
+        delay 0.2
+    end repeat
+end tell

+ 33 - 0
export-passwords.txt

@@ -0,0 +1,33 @@
+set the logFile to ((path to desktop) as string) & "Passwords"
+set keychainPath to "/Users/andrewlewman/Desktop/my.keychain"
+
+-- write_to_file taken from http://www.macosxautomation.com/applescript/sbrt/sbrt-09.html
+on write_to_file(this_data, target_file, append_data)
+    try
+        set the target_file to the target_file as string
+        set the open_target_file to open for access file target_file with write permission
+        if append_data is false then set eof of the open_target_file to 0
+        write this_data to the open_target_file starting at eof
+        close access the open_target_file
+        return true
+    on error
+        try
+            close access file target_file
+        end try
+        return false
+    end try
+end write_to_file
+
+tell application "Usable Keychain Scripting"
+    set keychainItems to get every keychain item of keychain keychainPath
+    repeat with keychainItem in keychainItems
+        set aServer to server in keychainItem
+        set anAccount to account in keychainItem
+        set aPassword to password in keychainItem
+
+        set csvEntry to aServer & "," & anAccount & "," & aPassword & "
+"
+
+        my write_to_file(csvEntry, logFile, true)
+    end repeat
+end tell

+ 12 - 0
extra-automation-v2.txt

@@ -0,0 +1,12 @@
+tell application "System Events"
+	repeat while exists (processes where name is "SecurityAgent")
+		try -- added
+			tell process "SecurityAgent"
+				click button "Allow" of window 1
+			end tell
+		on error -- added
+			-- ignore it -- added
+		end try -- added
+		delay 0.2
+	end repeat
+end tell

+ 148 - 0
get-passwords-from-safari-v2.txt

@@ -0,0 +1,148 @@
+> -- OPEN SAFARI. GOTO PREFERENCES. CLICK PASSWORDS TAB --
+-- THIS FIRST REPEAT SECTION IS JUST TO GET TO THE PASSWORDS SCREEN AND LOGIN TO ICLOUD --
+repeat 1 times
+    tell application "Safari"
+        activate
+        delay 0.5
+        tell application "System Events"
+            -- Ensure Password Field Selected --
+            keystroke tab
+            delay 0.2
+            -- Type your password for you --
+            keystroke "PASSWORD"
+            delay 0.2
+            -- Hit enter to login --
+            keystroke return
+            delay 0.2
+        end tell
+    end tell
+end repeat
+
+-- START GRABBING PASSWORDS - SET REPEAT VALUE TO NUMBER OF PASSWORDS --
+set x to 1
+repeat while (x ≤ 207)
+    -- Switch To Safari --
+    tell application "Safari"
+        activate
+        delay 0.5
+        tell application "System Events"
+            -- Switch from search field to password list field (Only needs to be done once) --
+            if (x = 1) then
+                keystroke tab
+                delay 0.2
+            end if
+            -- Select first password in list (Field selected. but nothing highlighted) --
+            key code 125
+            delay 0.2
+            -- Open Right-click Menu -- 
+            tell application process "Safari"
+                set _selection to value of attribute "AXFocusedUIElement"
+                tell _selection to perform action "AXShowMenu"
+            end tell
+            -- Down arrow once to choose/highlight "Copy Website" --
+            key code 125
+            delay 0.2
+            -- Copy Website/URL data --
+            keystroke return
+            delay 0.2
+        end tell
+    end tell
+    -- Switch To TextEdit
+    tell application "TextEdit"
+        activate
+        delay 0.5
+        tell application "System Events"
+            -- Print a double quote --
+            keystroke "\""
+            delay 0.2
+            -- Paste "Website/URL" data to text file --
+            keystroke "v" using command down
+            delay 0.2
+            -- Print ending double quote and a comma for CSV --
+            keystroke "\","
+            delay 0.2
+            -- Print a double quote --
+            keystroke "\""
+            delay 0.2
+            -- Paste "Websites" data to text file again (For "Title" field in 1Password) --
+            keystroke "v" using command down
+            delay 0.2
+            -- Print ending double quote and a comma for CSV --
+            keystroke "\","
+            delay 0.2
+        end tell
+    end tell
+    -- Switch To Safari --
+    tell application "Safari"
+        activate
+        delay 0.5
+        tell application "System Events"
+            -- Open Window containing "User Name", "Password" and "Websites" fields --
+            keystroke return
+            delay 0.2
+            -- Move to "User Name" field --
+            keystroke tab
+            delay 0.2
+            -- Copy data from "User Name" field --
+            keystroke "c" using command down
+            delay 0.2
+        end tell
+    end tell
+    -- Switch To TextEdit --
+    tell application "TextEdit"
+        activate
+        delay 0.5
+        tell application "System Events"
+            -- Print a double quote --
+            keystroke "\""
+            delay 0.2
+            -- Paste "User Name" data to text file --
+            keystroke "v" using command down
+            delay 0.2
+            -- Print ending double quote and a comma for CSV --
+            keystroke "\","
+            delay 0.2
+        end tell
+    end tell
+    -- Switch To Safari --
+    tell application "Safari"
+        activate
+        delay 0.5
+        tell application "System Events"
+            -- Move to "Password" field --
+            keystroke tab
+            delay 0.2
+            -- Copy from "Password" field --
+            keystroke "c" using command down
+            delay 0.2
+        end tell
+    end tell
+    -- Switch To TextEdit --
+    tell application "TextEdit"
+        activate
+        delay 0.5
+        tell application "System Events"
+            -- Print a double quote --
+            keystroke "\""
+            delay 0.2
+            -- Paste "Websites" data to text file --
+            keystroke "v" using command down
+            delay 0.2
+            -- Print ending double quote and start a new line --
+            keystroke "\""
+            keystroke return
+        end tell
+    end tell
+    -- Switch To Safari --
+    tell application "Safari"
+        activate
+        delay 0.5
+        tell application "System Events"
+            -- Click "Done" button --
+            keystroke return
+            delay 0.2
+        end tell
+    end tell
+    set x to (x + 1)
+end repeat
+end run

+ 148 - 0
get-passwords-from-safari.txt

@@ -0,0 +1,148 @@
+> -- OPEN SAFARI. GOTO PREFERENCES. CLICK PASSWORDS TAB --
+-- THIS FIRST REPEAT SECTION IS JUST TO GET TO THE PASSWORDS SCREEN AND LOGIN TO ICLOUD --
+repeat 1 times
+    tell application "Safari"
+        activate
+        delay 0.5
+        tell application "System Events"
+            -- Ensure Password Field Selected --
+            keystroke tab
+            delay 0.2
+            -- Type your password for you --
+            keystroke "PASSWORD"
+            delay 0.2
+            -- Hit enter to login --
+            keystroke return
+            delay 0.2
+        end tell
+    end tell
+end repeat
+
+-- START GRABBING PASSWORDS - SET REPEAT VALUE TO NUMBER OF PASSWORDS --
+set x to 1
+repeat while (x ≤ 207)
+    -- Switch To Safari --
+    tell application "Safari"
+        activate
+        delay 0.5
+        tell application "System Events"
+            -- Switch from search field to password list field (Only needs to be done once) --
+            if (x = 1) then
+                keystroke tab
+                delay 0.2
+            end if
+            -- Select first password in list (Field selected. but nothing highlighted) --
+            key code 125
+            delay 0.2
+            -- Open Right-click Menu -- 
+            tell application process "Safari"
+                set _selection to value of attribute "AXFocusedUIElement"
+                tell _selection to perform action "AXShowMenu"
+            end tell
+            -- Down arrow once to choose/highlight "Copy Website" --
+            key code 125
+            delay 0.2
+            -- Copy Website/URL data --
+            keystroke return
+            delay 0.2
+        end tell
+    end tell
+    -- Switch To TextEdit
+    tell application "TextEdit"
+        activate
+        delay 0.5
+        tell application "System Events"
+            -- Print a double quote --
+            keystroke "\""
+            delay 0.2
+            -- Paste "Website/URL" data to text file --
+            keystroke "v" using command down
+            delay 0.2
+            -- Print ending double quote and a comma for CSV --
+            keystroke "\","
+            delay 0.2
+            -- Print a double quote --
+            keystroke "\""
+            delay 0.2
+            -- Paste "Websites" data to text file again (For "Title" field in 1Password) --
+            keystroke "v" using command down
+            delay 0.2
+            -- Print ending double quote and a comma for CSV --
+            keystroke "\","
+            delay 0.2
+        end tell
+    end tell
+    -- Switch To Safari --
+    tell application "Safari"
+        activate
+        delay 0.5
+        tell application "System Events"
+            -- Open Window containing "User Name", "Password" and "Websites" fields --
+            keystroke return
+            delay 0.2
+            -- Move to "User Name" field --
+            keystroke tab
+            delay 0.2
+            -- Copy data from "User Name" field --
+            keystroke "c" using command down
+            delay 0.2
+        end tell
+    end tell
+    -- Switch To TextEdit --
+    tell application "TextEdit"
+        activate
+        delay 0.5
+        tell application "System Events"
+            -- Print a double quote --
+            keystroke "\""
+            delay 0.2
+            -- Paste "User Name" data to text file --
+            keystroke "v" using command down
+            delay 0.2
+            -- Print ending double quote and a comma for CSV --
+            keystroke "\","
+            delay 0.2
+        end tell
+    end tell
+    -- Switch To Safari --
+    tell application "Safari"
+        activate
+        delay 0.5
+        tell application "System Events"
+            -- Move to "Password" field --
+            keystroke tab
+            delay 0.2
+            -- Copy from "Password" field --
+            keystroke "c" using command down
+            delay 0.2
+        end tell
+    end tell
+    -- Switch To TextEdit --
+    tell application "TextEdit"
+        activate
+        delay 0.5
+        tell application "System Events"
+            -- Print a double quote --
+            keystroke "\""
+            delay 0.2
+            -- Paste "Websites" data to text file --
+            keystroke "v" using command down
+            delay 0.2
+            -- Print ending double quote and start a new line --
+            keystroke "\""
+            keystroke return
+        end tell
+    end tell
+    -- Switch To Safari --
+    tell application "Safari"
+        activate
+        delay 0.5
+        tell application "System Events"
+            -- Click "Done" button --
+            keystroke return
+            delay 0.2
+        end tell
+    end tell
+    set x to (x + 1)
+end repeat
+end run