---
 contrib/pass.applescript | 41 ++++++++++++++++++++++++++++-------------
 1 file changed, 28 insertions(+), 13 deletions(-)

diff --git a/contrib/pass.applescript b/contrib/pass.applescript
index 1b9a16d..363ea7d 100644
--- a/contrib/pass.applescript
+++ b/contrib/pass.applescript
@@ -43,28 +43,43 @@ else -- if (lang = "en")
        set nClear to "Forget"
 end if
 
+-- Save active window
+tell application "System Events"
+       set activeProc to first application process whose frontmost is true
+       log activeProc
+end tell
+
 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 & "; source 
~/.gpg-agent-info; pass " & entity & " | head -n1"
        
        set the clipboard to pw
-       
-       -- 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
-                       end tell
-                       delay 1
-               else
-                       exit repeat
-               end if
-       end repeat
 on error errMsg
        display dialog errMsg with title nTitle with icon stop
+       -- Restore active window
+       tell application activeApp
+               activate window activeWin
+       end tell
 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
+               end tell
+               delay 1
+       else
+               exit repeat
+       end if
+end repeat
+
 -- Clear clipboard
 set the clipboard to ""
 closeNotifications()
-- 
2.3.0

_______________________________________________
Password-Store mailing list
[email protected]
http://lists.zx2c4.com/mailman/listinfo/password-store

Reply via email to