pass.applescript (3004B)
1 --------------------------------------------------------------------------------------------- 2 -- Applescript for easy invocation of 'pass' 3 --------------------------------------------------------------------------------------------- 4 -- 5 -- Author: Steffen Vogel <post@steffenvogel.de> 6 -- Tested with: OS X 10.10 Yosemite 7 -- 8 -- Installation: 9 -- 10 -- 1. Copy this script to /Library/Scripts/pass.applescript 11 -- 12 -- 2. Use the Automator to create a service which starts the following AppleScript: 13 -- 14 -- on run {input, parameters} 15 -- run script POSIX file "/Library/Scripts/pass.applescript" 16 -- end run 17 -- 18 -- 3. Install the application 'Notifications Scripting' from: 19 -- http://www.cooperative-fruitiere.com/notifications/NotificationsScripting.dmg 20 -- 21 -- 4. Go to 'System Settings' -> 'Keyboard' to create a short cut for the service 22 -- you created before 23 -- 24 -- 5. Go to 'System settings' -> 'Notifications' -> choose 'Notifications Scripting' 25 -- -> and switch from 'Banners' to 'Alerts' 26 -- 27 --------------------------------------------------------------------------------------------- 28 29 -- Configuration 30 property defPass : "root" 31 property clearAfter : 45 32 property shellPath : "/opt/local/bin:/usr/local/bin:$PATH" 33 34 -- Translation 35 set lang to user locale of (get system info) 36 if (lang = "de_DE") then 37 set nTitle to "Password-store" 38 set nPrompt to "Welches Password wird benštigt?" 39 set nClear to "Vergesse" 40 else -- if (lang = "en") 41 set nTitle to "Password-store" 42 set nPrompt to "Which password do you want?" 43 set nClear to "Forget" 44 end if 45 46 try 47 set entity to the text returned of (display dialog nPrompt default answer defPass buttons {"OK"} with title nTitle default button 1) 48 set pw to do shell script "export PATH=" & shellPath & "; pass " & entity 49 50 set the clipboard to pw 51 52 -- Wait until clipboard changed then close notification 53 repeat with secsLeft from 0 to clearAfter 54 if pw is equal to (the clipboard) then 55 tell application "Notifications Scripting" 56 set event handlers script path to (path to me) 57 display notification nTitle id "pass" message "Password copied to clipboard (" & (clearAfter - secsLeft) & " secs left)" action button nClear with has action button 58 end tell 59 delay 1 60 else 61 exit repeat 62 end if 63 end repeat 64 on error errMsg 65 display dialog errMsg with title nTitle with icon stop 66 end try 67 68 -- Clear clipboard 69 set the clipboard to "" 70 closeNotifications() 71 72 -- Handle click to notification: 73 using terms from application "Notifications Scripting" 74 on notification activated 75 set the clipboard to "" 76 end notification activated 77 end using terms from 78 79 -- Close all Notifications 80 on closeNotifications() 81 tell application "System Events" 82 tell process "NotificationCenter" 83 set theWindows to every window 84 repeat with i from 1 to number of items in theWindows 85 set this_item to item i of theWindows 86 try 87 click button 1 of this_item 88 end try 89 end repeat 90 end tell 91 end tell 92 end closeNotifications