问题
This is one of my first times using Xcode/AppleScript in my life - so sorry if very stupid question. Anyway, I have a little test window under my MainMenu.xib file. I've set up a tab view with different buttons and things under each tab that have all sorts of random test functions (displaying dialogs, saying things, requesting passwords, etc.). In one tab, I want to have a lot of test content, but in another tab I only want a little. Is it possible, when you change tab, to have it resize the window to specified dimensions? Also, I've made my window un-resizeable (otherwise the formatting gets all messed up when resized), and would it be possible to allow this resizing, even if you can't resize with the mouse? Sorry if this doesn't make any sense, I'll be happy to clarify should anyone need it. Any help would be appreciated, I've been googling for quite a bit.
回答1:
To resize windows in applescript, you can use this command:
tell current application to set the bounds of the front window to {24, 96, 524, 396}
So if you want to activate such a script, put this in your AppDelegate.applescript:
on tabclick1_(aNotification)
tell current application to set the bounds of the front window to {24, 96, 524, 396}
end tabclick1_
You can then connect this to a tab button, and set the bounds of the window as you like.
You can, of course copy this, but then change the name "tabclick1_", and the bounds, and then connect it to another tab. So each time you click a tab, it will activate its appropriate script (for example "tabclick1_"), and that script will change the bounds of the window.
But you will have to make your window resizable, and anchor your objects correctly.
Important:
- The first item of the bounds is the distance in pixels from the left side of your screen to the left side of your window.
- The second item of the bounds is the distance in pixels from the top of your screen to the top of your window.
- The third item of the bounds is the distance in pixels from the left side of your screen to the right side of your window.
- The fourth item of the bounds is the distance in pixels from the top of your screen to the bottom of your window.
来源:https://stackoverflow.com/questions/15148413/use-applescript-to-resize-a-window-in-xcode