[pass] [PATCH] applescript: improved several parts of the applescript integration
Steffen Vogel
post at steffenvogel.de
Sun Jul 26 16:06:14 CEST 2015
Note: This patch is againt the previous one, I posted:
[PATCH] applescript: restore last active window after password has been copied to clipboard
The previous focused window gets now restored immeadiatly after the
dialog has been closed (instead of waiting for pass to return)
The notification includes now the name of the password
The closing of remaining notifications has been put into a try/catch
block. Otherwise the script would throw an error if it does not own the
neccessary permissions (see point 6 in the description)
---
contrib/pass.applescript | 33 +++++++++++----------------------
1 file changed, 11 insertions(+), 22 deletions(-)
diff --git a/contrib/pass.applescript b/contrib/pass.applescript
index c71fd93..e5da495 100644
--- a/contrib/pass.applescript
+++ b/contrib/pass.applescript
@@ -47,30 +47,27 @@ else -- if (lang = "en")
end if
-- Save active window
-tell application "System Events"
- set activeProc to first application process whose frontmost is true
-end tell
+tell application "System Events" to set activeProc to first application process whose frontmost is true
+
+-- Get entity from dialog
+set entity to the text returned of (display dialog nPrompt default answer defPass buttons {"OK"} with title nTitle default button 1)
+
+-- Restore previously active window
+tell application "System Events" to set the frontmost of activeProc to true
try
- set entity to the text returned of (display dialog nPrompt default answer defPass buttons {"OK"} with title nTitle default button 1)
set pw to do shell script "export PATH=" & shellPath & "; pass " & entity
-
set the clipboard to pw
on error errMsg
display dialog errMsg with title nTitle with icon stop
end try
--- Restore last active App
-tell application "System Events"
- set the frontmost of activeProc to true
-end tell
-
-- Wait until clipboard changed then close notification
repeat with secsLeft from 0 to clearAfter
if pw is equal to (the clipboard) then
tell application "Notifications Scripting"
set event handlers script path to (path to me)
- display notification nTitle id "pass" message "Password copied to clipboard (" & (clearAfter - secsLeft) & " secs left)" action button nClear with has action button
+ display notification nTitle id "pass" message "'" & entity & "' copied to clipboard " & return & " (" & (clearAfter - secsLeft) & " secs left)" action button nClear with has action button
end tell
delay 1
else
@@ -81,17 +78,9 @@ end repeat
-- Clear clipboard
set the clipboard to ""
--- Close all pending Notifications
-tell application "System Events"
- tell process "NotificationCenter"
- set theWindows to every window
- repeat with i from 1 to number of items in theWindows
- set this_item to item i of theWindows
- try
- click button 1 of this_item
- end try
- end repeat
- end tell
+-- Close pending Notification
+tell application "Notifications Scripting"
+ display notification nTitle id "pass" message "Password has been cleared" has action button false
end tell
-- Handle notification action: forget password
--
2.3.0
More information about the Password-Store
mailing list