简体   繁体   中英

Possible to script the "Export" command in Microsoft Outlook 2019 on Apple OS?

I'm trying to automate export of my calendar on Outlook 2019 on Apple OS 10.13; I don't see the Export command in the scripting dictionary of the application. Am I missing it? Is there a better way to automate this?

What is Apple OS? Is it MacOS??? My Microsoft Outlook version is "version 16.29 (19090802)", the code below works on my MacOS 10.12.6. You can try if it works on your machine.

tell application "Microsoft Outlook"
    activate
    delay 0.3
end tell
tell application "System Events"
    tell process "Microsoft Outlook"
        set theExportAsName to "Outlook for Mac Archive.olm"
        set theExportToFolder to "/Users/admin/Desktop"
        --input the file name and the destination folder path you want to export as
        tell menu item "Export..." of menu "File" of menu bar item "File" of menu bar 1
            click
            delay 0.5
        end tell
        --show the Export dialog (1/3), we need to deal with three dialogs totally.
        --knowledge point 1: how to click menu item in APP menu bar
        tell group 1 of group "What do you want to export?" of front window
            if value of radio button "Items of these types:" is not 1 then
                click radio button "Items of these types:"
            end if
        end tell
        --1st we choose export items
        tell group 1 of group 1 of group "What do you want to export?" of front window
            if value of checkbox "Mail" is not 0 then
                click checkbox "Mail"
            end if
            if value of checkbox "Calendar" is not 1 then
                click checkbox "Calendar"
            end if
            if value of checkbox "Contacts " is not 0 then
                click checkbox "Contacts "
            end if
        end tell
        tell group 2 of group 1 of group "What do you want to export?" of front window
            if value of checkbox "Notes" is not 0 then
                click checkbox "Notes"
            end if
            if value of checkbox "Tasks" is not 0 then
                click checkbox "Tasks"
            end if
        end tell
        --2nd we check Calendar, uncheck all the others
        click button "Continue" of front window
        delay 0.5
        --3rd click Continue button to go to next dialog window (2/3)
        tell text field 1 of sheet 1 of front window
            set value to theExportAsName
        end tell
        --1st we set the file name we want to use
        set the clipboard to theExportToFolder
        keystroke "G" using {command down, shift down}
        delay 0.5
        keystroke "v" using {command down}
        delay 0.5
        keystroke return
        delay 0.5
        --2nd we set the destination folder path we want to use
        tell sheet 1 of front window
            click button "Save"
            delay 0.5
        end tell
        --3rd click Save button to go to the last dialog window (3/3)
        tell front window
            click button "Finish"
        end tell
        --1st click Finish button to finish this task
    end tell
end tell

Note 1: the delay duration is longer than needed, I set it to big number to make the code run slowly, to make you see what happened. You can test then set smaller delay value to speed up the running.

Note 2: to these three dialog window, I all use the code below to get information about the UI elements - to see how to reference them.

tell application "Microsoft Outlook"
    activate
    delay 0.3
end tell
tell application "System Events"
    tell process "Microsoft Outlook"
        tell front window
            set uiElems to entire contents
        end tell
    end tell
end tell

Note 3: I write some comments to explain each step of the code. You can test it on your machine. Please let me know if it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM