Visual Studio 代码和 AppleScript 的界限
Bounds of Visual Studio Code and AppleScript
如何使用 AppleScript 获取代码编辑器 Visual Studio Pro 的 window 的位置和大小?
这是我试过的:
tell application "Visual Studio Code" to get the bounds of window 1
--> error "Visual Studio Code got an error: Can’t get bounds of window 1." number -1728 from bounds of window 1
tell application "System Events"
tell process "Visual Studio Code"
position of window 1
size of window 1
end tell
end tell
--> error "System Events got an error: Can’t get process \"Visual Studio Code\"." number -1728 from process "Visual Studio Code"
Visual Studio Code 没有 AppleScript 字典文件 ,例如:
${AppName}.app/Contents/Resources/${AppName}.sdef
因此,使用 AppleScript 编写脚本将受到限制。
Visual Studio 代码的 可执行文件是:
Visual Studio Code.app/Contents/MacOS/Electron
还有其他应用程序使用 Electron,一个应用程序 运行 可能不止一个使用 Electron,尝试使用 AppleScript 会进一步复杂化。
也就是说,以下 示例 AppleScript code 对我有用:
tell application "System Events" to ¬
get {position, size} of window 1 of process "Electron"
您可以使用名为“代码”的进程:
tell application "System Events" to tell process "Code"
tell window 1
set size to {1024, 768}
set position to {100, 100}
end tell
end tell
如何使用 AppleScript 获取代码编辑器 Visual Studio Pro 的 window 的位置和大小?
这是我试过的:
tell application "Visual Studio Code" to get the bounds of window 1
--> error "Visual Studio Code got an error: Can’t get bounds of window 1." number -1728 from bounds of window 1
tell application "System Events"
tell process "Visual Studio Code"
position of window 1
size of window 1
end tell
end tell
--> error "System Events got an error: Can’t get process \"Visual Studio Code\"." number -1728 from process "Visual Studio Code"
Visual Studio Code 没有 AppleScript 字典文件 ,例如:
${AppName}.app/Contents/Resources/${AppName}.sdef
因此,使用 AppleScript 编写脚本将受到限制。
Visual Studio 代码的 可执行文件是:
Visual Studio Code.app/Contents/MacOS/Electron
还有其他应用程序使用 Electron,一个应用程序 运行 可能不止一个使用 Electron,尝试使用 AppleScript 会进一步复杂化。
也就是说,以下 示例 AppleScript code 对我有用:
tell application "System Events" to ¬
get {position, size} of window 1 of process "Electron"
您可以使用名为“代码”的进程:
tell application "System Events" to tell process "Code"
tell window 1
set size to {1024, 768}
set position to {100, 100}
end tell
end tell