I created a macro to open an Excel password protected file but have a number of questions. The macro is the first of the two macros below.
QUESTION 1: Is there a better (i.e. more secure) way of entering the password (i.e. I have entered it as text). There are two scenarios here a) for password protected files that do NOT us a password manager and b) for webpages whose passwords are stored in 1Password.
QUESTION 2: In testing the application I noticed that I needed a delay after opening the file. I would like to change the pause from 10 seconds to until the file is opened. Is there a way to do this noting I did try Pause Until Condition Met but that did not work (i.e. the macro failed o execute which I suspect because it is at the front immediately before it has finished loading).
QUESTION 3: In the last step of the if statement I delete the Excel sheet called SHEET. XLSX. Is there a more elegant way to do this such as s to delete all sheets that are called / titled the sheet that I opened?
PROBLEM 1: With respect to the second bundles macro which includes AppleScript. This macro did not work when I decided to use brute force and write an AppleScript. The AppleScript works perfectly as an AppleScript but does a) NOT work within KM and b) results in the following error message. Would like to know / understand why.
Worth noting, I do believe that I have the proper accessibility per:
When I run the macro I get the following error code:
Would very much appreciate your help with the above.
The next time you run the macro and get that error message, try opening the KM Engine log (Help > Open Logs Folder), find the full error message text, and tell us what that says.
You can get passwords from the keychain using Keyboard Maestro or the security shell command.
This works in Microsoft Office 2016 on Mojave:
# Open a Password Protected Workbook or Worksheet.
set passwd to "1234" -- whatever you want
set theWbpath to "/Users/xxxxx/Desktop/number1.xlsx" -- example path
set theWb to "number1.xlsx" -- example file
set theSheet to "sheet1" -- example name of sheet
tell application "Microsoft Excel"
open theWbpath
unprotect workbook theWb password passwd
# or
unprotect sheet theSheet password passwd
end tell
This works in Microsoft Office 2016 on Mojave.
# Delete a Worksheet.
tell application "Microsoft Excel"
set display alerts to false
set sheetList to sheets whose name starts with "N"
if length of sheetList = 1 then
delete item 1 of sheetList
end if
set display alerts to true
end tell
You cannot script 1Password, and they've stated they will never make it scriptable. Please do complain.
The way to use pause-until for an application is:
Pause until app is frontmost.
KM can still operate before the app is ready.
Pause until a menu path is enabled.
Using a path is faster than a menu item name, because KM doesn't have to search – it has a reference.
Unfortunately it only works conditionally @ccstone. I had already sent @Joel a suggestion with 1Password yesterday.
In my example I have the Excel document on the desktop.
By entering the shortcut, this is called and after the login dialog appears in the foreground, that 1Password autofill login is performed.
In my gif, the Excel document is opened once with 1Password Mini unlocked and then the KM macro pauses until you enter your master password.