将AppleScript与Apple事件结合使用我可以获得powerpoint Mac的位置,但它需要辅助访问。
tell application "System Events"
tell process "Microsoft PowerPoint"
properties of UI element 1 of window 1
end tell
end tell
如何在没有辅助访问的情况下访问该位置,是否可以使用VBA或shell脚本?
答案 0 :(得分:1)
Your code block is trying to retrieve the properties of a GUI object in the front window. However, position is not one of the properties that is attributed to the UI element
class.
If you're trying to get the position of Powerpoint's window, you're in luck: you don't need assistive access. Both System Events and Powerpoint can relay positional information of windows as standard properties.
Using Powerpoint:
tell application "Microsoft Powerpoint" to return the bounds of the active window
--> e.g. {260, 23, 1280, 800}
This returns a list of four integers, the first two of which represent the coordinates of the window's upper-left corner, and the last two of which represent the coordinates of the bottom-right corner.
Using System Events:
tell application "System Events" to get [position, size] of window 1 of process "Microsoft Powerpoint"
--> e.g. {{260, 23}, {1020, 777}}
This returns the position and size, each as pairs of integers. The pair of position
values denotes the window's top-left coordinate, and you can see it matches the first pair of values from bounds
. The pair of size
values denotes the window's width and height, respectively.
Also notice that if you take the latter pair of bounds
values and subtract the first pair, this matches the pair of size
values given here.
Therefore, if bounds
is represented by a list of four variables {x, y, a, b}
, then position
is given by {x, y}
and size
is given by {a - x, b - y}
.
You can also set both size and position using either the bounds
or size
/position
properties by way of a set
command:
tell app "Microsoft Powerpoint" to set the bounds of its active window to {x, y, a, b}
or
tell app "System Events" to tell process "Microsoft Powerpoint" to tell window 1 to set its size to {w, h}
答案 1 :(得分:0)
这适用于我最新版本的Sierra
property currentBounds : {}
property theApp : "Microsoft Powerpoint" -- Whatever App You Want
property thePosition : {0, 22} -- Replace With Desired Numbers
property theSize : {190, 158} -- Replace With Desired Numbers
property setNewBounds : thePosition & theSize
getBounds()
-- setBounds() -- Un-Comment This For Setting Bounds
on getBounds()
activate application theApp
delay 1
tell application (path to frontmost application as text)
set currentBounds to bounds of window 1
end tell
end getBounds
on setBounds()
try
activate application theApp
delay 1
tell application (path to frontmost application as text)
set bounds of window 1 to setNewBounds
end tell
on error
activate application theApp
delay 1
tell application "System Events" to tell window 1 of (process 1 where it is frontmost)
try
set position to thePosition
set size to theSize
end try
end tell
end try
end setBounds