move any window outside screen under Mac OS - macos

I am trying to hide (or to move outside teh screen bounds) any window (I mean not belonging to my application).
I tried using Accessibility but unfortunately, there is always a small part of the window which is still on the screen.
Here are my questions:
- Is there a way to completly move a window outside the screen using accessibility?
- Is there an alternative way (Apple Script, ...) to achive that?
Thanks!
I am also using Lion and I am quite sure it was working before.
I am discovering a lot of small things like that in 10.7.
Apple have introduced more changes that it seem.
Thanks for your trial.

I tried the following code with a TextEdit window. It wouldn't work. I tried to move it off all 4 sides of the screen and none of it worked (as you explained there's always a part of the window showing). I'm using 10.7. I'm pretty sure I could do it in 10.6 and earlier... maybe it's a 10.7 thing???
tell application "System Events"
tell process "TextEdit"
set theWindows to windows
repeat with aWindow in theWindows
tell aWindow
set currentPosition to position
set position to {-1000, item 2 of currentPosition}
end tell
end repeat
end tell
end tell

Related

Move all open applications to current desktop "space" with applescript

I have been searching endlessly with no avail on how to move a window between spaces on macos in applescript. The seemingly basic thing I want to do is move all open application windows from any space to the first space. If anyone out there can help, please reach out. There seems to be no straight forward way in doing this in the latest version of macos (Mojave 10.14.4). I am also open to doing this in any another language that will interact with macos if it is possible/simpler.
tell application "System Events"
repeat with proc in application processes where background only is false
tell proc
log "found app: " & name
set processName to name
log count of windows
repeat with win in windows
-- move window to first "space"
end repeat
end tell
end repeat
end tell
I think the only way to do this is just simulating moving spaces using
tell application "System Events" to key code 19 using {control down}
but then your desktop will bounce for each app like crazy.
There's a window manager for macOS called Phoenix that's scriptable using JavaScript.
I wrote a Phoenix script, phoenix-move-windows that moves windows based on the current monitor and screen layout. It is configurable so that it will move windows to a specified position, and you can have different arrangements based on the current number of screens, and number of spaces on each screen.
It does support moving all windows to a specified screen and space, using the "defaultBinding" in an arrangement.

Looking for a way to set (default) zoom level of iWorks app

Scanning the internet I found that in the past one could set the view scale or fit width of an iWorks application like this in Applescript:
tell window 1 of application "Keynote"
set fit width to true
end tell
or
tell window 1 of application "Keynote"
set view scale to 80
end tell
Both these methods don't work in Yosemite anymore (and most likely did not work since Snow Leopard according to some Google searches.
I also looked through the Applescript API Library for Keynote and could not see anything that refers to a view scale or zoom level.
Is there really no way anymore to set these via AppleScript?
My end goal is actually just to have new iWorks apps always be set to "Fit in Window", but lacking the possibility to set and save it via a Theme, I was assuming that AppleScript would be the only possible solution.

Applescript: how can I perform an action on all Finder windows, only in current desktop?

On Mountain Lion, I'm trying to create an AppleScript app to resize all Finder windows in the current Desktop (aka space).
I'd like to simply navigate to the space in question, click an app, and have it resize all open Finder windows -- in that space only -- to a fixed size.
I've got a script to do what I need, but it operates on every Finder window, across ALL spaces. How can I limit it to the current space? Thank you.
tell application "Finder"
set theFolders to folder of every window
set theBounds to {10, 10, 310, 310}
repeat with aFolder in theFolders
tell container window of aFolder
set toolbar visible to false
set bounds to theBounds
end tell
end repeat
end tell
This code stacks windows on top of one another. That's not a problem. I know how to cascade if I want, but I currently prefer to manually position them using "divvy".
I'm running this resize code to work around a Mountain Lion "feature" that limits minimum Finder window widths, and interaction with the side panel toolbar. This code does what I want, just on too many windows.

Apple Script: Resize and position Virtual Keyboard / KeyboardViewer

If these are too many questions in 1, please tell me it and I edit the question and split it into 3? question.
I am currently writing some apple scripts and tried some things with it.
I want to:
open virtual keyboard (keyboardViewer)
resize it
position it
deactivate controls like close restore and minimize
My scripts are these:
App 1:
tell application "System Events"
if not (exists (process "KeyboardViewer")) then
do shell script "/usr/bin/keyboardViewer"
end if
end tell
App 2:
tell application "System Events"
if exists (process "KeyboardViewer") then
click (process "KeyboardViewer"'s window 1's buttons whose subrole is "AXCloseButton")
end if
end tell
I am using the keyboardViewer by https://github.com/nriley/keyboardViewer in /usr/bin/
Seems I can not script my application. Resizing and positioning works with some applications but not with this one. Also hiding the controls on the top left of the window in mac os x is not possible.

How do I make a Safari window active using AppleScript (elegantly)?

While one can simulate command-shift-` using System Events to change windows in Safari, is there no better way to do this with AppleScript? I can change the index of Safari's windows, this changes their ordering on the screen but does not make them active. Suppose you have two Safari windows containing about:blank -- how could you bring the one in the back to the front and make it active?
Granted, command-shift-` works, so maybe there only needs to be one way to skin this cat.
I also noticed that changing the index does reorder the windows however the new window does not actually come to the front. By playing around I found you can fix that by playing with the "visible" property...
tell application "Safari"
set theWindows to windows
set win2 to item 2 of theWindows
tell win2
set visible to false
set visible to true
set index to 1
end tell
end tell

Resources