How to open word document with known password using applescript? - ms-word

I need to open a protected Microsoft Word document via AppleScript.
I know the password, but i can't figure out how to code it with AppleScript.
I tried some variations of AppleScript code, without success.
set the myfile to ("/Users/alemac/Desktop/teste.docx")
tell application "Microsoft Word"
open myfile password document "123"
end tell
Word opens the file (like Finder does), and the password dialog opens waiting for password.

After running your version of the AppleScript code several times, the command open myfile password document actually worked for me maybe 3 or 4 sporadic times. Eventually it stopped working and the password dialog box opened every time. After wracking my brain trying to figure out why this was happening, for nearly an hour, I reluctantly decided to use UI scripting to handle the password dialog box, in the event it reared its ugly head.
This AppleScript code works for me using the latest version of macOS Mojave and Microsoft Word version 16.24
set the myfile to (path to desktop as text) & "teste.docx"
set thePassword to 123
tell application "Microsoft Word"
activate
ignoring application responses
open myfile password document thePassword
delay 1
end ignoring
end tell
try
tell application "System Events"
repeat until exists of window "Password" of application process "Word"
delay 0.1
end repeat
click window "Password" of application process "Word"
delay 0.2
click text field 1 of window "Password" of application process "Word"
delay 0.2
keystroke thePassword
delay 0.2
keystroke return
end tell
end try

Related

How to fix error while working with Microsoft.Office.Interop.Word

I am writing a simple Winforms app to generate 44 separate letters from a MS Word template. I get data to each letter from a local SQL Server database. While running the generate letters method I get the error shown here randomly. I am using Microsoft.Office.Interop.Word to do this:
The last time you opened x.docx, it caused a serious error. Do you still want to open it?
When I click No the program exits and when clicked Yes it continues. I manually re-enabled the file in Word options - Add-ins, and I have read solutions about registry editing and questions like this.
Why does this happen, and how can I fix this issue?

Word, Excel web add-in prompts save dialog

Just wondering if I am experiencing an expected behavior - when I open my MS Word Web add-in and I want to close the document it prompts me if I want to save changes even I haven't changed anything on purpose. Let me know if there is a way not to pop up that dialog.
Thanks,
AU

Prevent Word on Mac to automatically follow hyperlinks on click

I am developing a Word Add-in application that should work on Word application for both Windows and Mac. I have a problem specific to Word on Mac, while Word on Windows and Word online work as expected.
For business logic reasons my add-in application needs to create and update hyperlinks in the word document. The hyperlink gets updated once the user clicks on it in the document. However, the default behaviour of the Word on Mac is to automatically navigate user to the browser with the hyperlink URL, once he/she clicks on the hyperlink. Incidentally, if you press CMD + click on a Mac, you won't be navigated away from the application.
Is it possible to programatically (using Office/Word Api from the JS driven add-in application) prevent that kind of behaviour on hyperlinks when clicked?
If not, is it possible to capture and cancel the cursor click event on the hyperlink? Or capture it and maybe emit a new event which would simulate "CMD + click", with effect to not navigate from the document?

SWFUpload to upload files to website using PowerShell

I am trying to use PowerShell to automate the process of loading files to a website.
The process has four steps. I have automated the first three steps of the process by using getElementByID to fill values of textboxes and click buttons. The fourth step uploads the files. The website uses SWFUpload to upload the files. I cannot figure out how to trigger (fire event) the SWFUpload in PowerShell. I can trigger the other buttons using the .Click() method, but this does not work for the upload button. I suspect it is because it isn't really a button, but an SWFUpload utility (type=application/x-shockwave-flash).
Does anyone know how to trigger this in PowerShell? I can provide the HTML coding and the PowerShell script. I have referenced the website below, but it seems to show how to create the SWFUpload in JavaScript, not PowerShell.
https://www.chem.umn.edu/groups/gladfelter/blade_packs/system_CKeditor/plugins/pgrfilemanager/SWFUpload%20v2.2.0.1%20Core/Documentation/#swfupload
I did not find a way to work with SWFUpload in PowerShell, but I was able to find three work-arounds.
1.) SendKeys
2.) Mouse-click function via power shell : how to send middle mouse click?
3.) WASP https://wasp.codeplex.com/
I chose to use SendKeys because to use a mouse click, you must also move the mouse. This is possible, but it is so easy to nudge the mouse which would re-posisiton the mouse off of the button.
SendKeys allows the user to send keyboard keys to the computer without the user acutally doing anything. I used SendKeys to tab to the "Upload button", click it, navigate thru the Open File dialog box to select the files, and finally click the Open button to complete the upload.
There are some drawbacks to SendKeys, however. SendKeys will send the key(s) only to the window that is in the foreground. So if you are running your script and your computer sends you a pop-up message in the middle of it, SendKeys will send the keystrokes to that pop-up message.
SendKeys syntax:
http://blogs.technet.com/b/heyscriptingguy/archive/2011/01/10/provide-input-to-applications-with-powershell.aspx

Use Automator to email a word doc

I do work over a few computers and use my email address to keep an extra save copy of my files. I'd like to have an Automator service for Microsoft Word that sends an email to myself with the current word doc as an attachment and the title as the subject. If I could have a macro in Word that did the same thing that would also be great. Thanks.
You can either run this as an AppleScript by itself or insert the AppleScript in your Automator workflow.
tell application "Microsoft Word"
try
set theTitle to name of front document
end try
send mail front document
end tell
tell application "Mail"
activate
tell its outgoing message 1
set subject to theTitle
end tell
end tell