0

I am trying to use python package appscript to control applications in my MacBook. Unfortunately I am really confused.

For example, I am trying to control one of my excel files. I want to get the position and scroll to certain roll. Here is my code

# -*- coding:utf-8 -*-

from appscript import *

file = app('Microsoft Excel').documents[u'test.csv']
position = file.window.left_position()
print position

The code is only trying to get the position but it is not working. I download the ASDictionary to check the command but I still can not fix it. Here is the screenshot of the command:

enter image description here

Thank you so much for your help.

1 Answer 1

2

Excel’s Apple event (“AppleScript”) support is atypical and quirky.

  1. Avoid using documents; it doesn’t work correctly. Use workbooks instead.

  2. Workbooks don’t have a window property. They do, however, have windows elements (since you can view a workbook in more than one window).

Corrected Python code:

wb = app('Microsoft Excel').workbooks[u'test.csv']
position = wb.windows[1].left_position()
print(position)

Or, in AppleScript:

tell application "Microsoft Excel"
    tell workbook "test.csv"
        get left position of window 1
    end tell
end tell
Sign up to request clarification or add additional context in comments.

2 Comments

thank you so much. do you mind telling me how to get window id? I try "wb.windows[1].id()" but it is not working
Unlike most scriptable apps, Excel’s window doesn’t have an id property. You can only reference Excel windows by index or name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.