Funny issue with using automator to set quicktime window position - applescript

I'm using an applescript within automator to start a quicktime recording. When I run the applescript from automator, everything works fine, but when I run the same automator sequence as a double-clickable application, it throws an error* when it gets to this line:
tell application "System Events" to tell process "QuickTime Player" to set position of front window to {1131, 725}
Any ideas as to why?
Thanks!!
*The error is just, "The action “Run AppleScript” encountered an error"

You might be getting the error because your application doesn’t have permission to access GUI Scripting.
However, you can position and resize windows in QuickTime Player without GUI scripting like this:
tell application "QuickTime Player"
tell window 1
set the bounds to {100, 100, 640, 480}
end tell
end tell
The 4 numbers that set the bounds are the x position, y position, window width, window height. So the above script tells the first window to position itself 100 pixels away from the top of the screen, 100 pixels away from the left of the screen, and to be 640 pixels wide and 480 pixels tall.
Look in QuickTime Player’s AppleScript dictionary for the commands that enable you to start a recording with AppleScript. Open the Script Editor app and choose File > Open Dictionary and choose QuickTime Player.

Related

AppleScript Bounds moves app from current monitor

I record a lot of videos, so I have a MacBook Pro with two monitors connected. One of those monitors has a resolution set to 1920x1080. I record all my videos from that specific monitor. Right now, I run Google Chrome and Visual Studio Code. Then, I resize the windows for the specific conditions of my recording (sometimes Chrome uses more space, sometimes VSC does), so this is not a matter of simply doing a side-by-side setup where each app takes up a certain percentage.
That manual process is tedious and I usually want them to be a very specific size based on what I am recording. That is why I want to use AppleScript to simply resize the currently running applications based on various recording scenarios.
To create a test case, I wrote the following code. While it does the trick of perfectly resizing the app, it moves Chrome from the monitor I am recording on to my MacBook Pro's connected display.
Here is what I wrote so far:
set theApp to "Google Chrome"
set xLocation to 0
set yLocation to 0
set appWidth to 750
set appHeight to 1080
tell application "Google Chrome"
set bounds of front window to {0, 0, appWidth, appHeight}
end tell
Unfortunately, I am very new to AppleScript and have not been able to figure out how to prevent the script from moving the app (Google Chrome in this case) from the current monitor to the MacBook Pro monitor. I suspect it is that front window code, but I am struggling to learn how that works as I cannot find the documentation.
How can I use AppleScript to resize an application that is currently running without moving the application's window to another monitor?
I suppose if the answer is to open a new copy of the application, that would work too, so long as I can open or move it to the proper monitor. Thanks!
Update
Close, but not quite there...
I was provided this link in the comments. The code looks like this:
set theScreens to paragraphs of (do shell script "system_profiler SPDisplaysDataType -detailLevel |grep \"Resolution:\" | awk -F\"Resolution: \" '{print $2}'")
set theMonitor to ""
log theScreens
set the counter to count of theScreens --- set to 1 if you want to test it on monitor 1
if (counter) > 1 then
-- we will do things for monitor 2
set thisDisplayWidthHeightMonitor_2 to {(word 1 of item 1 of theScreens) + 2, 0, ((word 1 of item 1 of theScreens) + (word 1 of item 2 of theScreens)), word 3 of item 2 of theScreens}
set theMonitor to thisDisplayWidthHeightMonitor_2
else
-- we will do things for monitor 1
set thisDisplayWidthHeightMonitor_1 to {0, 0, (word 1 of item 1 of theScreens), (word 3 of item 1 of theScreens)}
set theMonitor to thisDisplayWidthHeightMonitor_1
end if
tell application "Safari"
activate
make new document with properties {URL:"http://netflix.com"}
set bounds of window 1 to theMonitor
log theMonitor
end tell
tell application "System Events"
tell application process "Safari"
set value of attribute "AXFullScreen" of window 1 to true
end tell
end tell
If I log the variable theScreens, I get the following result:
(*3072 x 1920 Retina, 3840 x 2160 (2160p/4K UHD 1 - Ultra High Definition), 4608 x 2592*)
That code does not show me the correct x position I need for my window placement. It just shows the monitors I am using and their UHD resolution.
When the code opens Safari (in this case), it sets the bounds with the variable theMonitor, and it does indeed open in the monitor I want it to. The output is:
3074, 0, 6912, 2160
Since the code does display the application in the monitor I want, I assume that 3074 is the correct x position for my need, so here is my updated code:
tell application "Google Chrome"
set bounds of front window to {3074, 0, 750, 1080}
end tell
Unfortunately, Google Chrome completely disappears off the screen and is nowhere to be found on any monitors or desktops. I have to quit Chrome and restart so I can use it again (or do the change the change-the-screen-resolution trick).
I am still left with the following question: How do I open the app in the correct monitor I desire and in the x & y location I desire?

Applescript how to change desktop mode (Fill Screen, Tile, Centre, etc)

Hi so I'm pretty new to applescript and trying to make an applescript program that has a list of 5 names, with corresponding images. So if someone clicks one of the buttons, desktop will change to that persons image.
Here is what I've got so far;
display dialog "Which Person?" buttons {"1", "2"}
if the button returned of the result is "1" then
tell application "System Events" to tell every desktop to set picture to "/Users/jamiecole/Desktop/TeacherTiles.app/Contents/Resources/Images/1.jpg"
else
tell application "System Events" to tell every desktop to set picture to "/Users/jamiecole/Desktop/TeacherTiles.app/Contents/Resources/Images/2.jpg"
end if
I need to make the mode to Tile, see this
screenshot. How can I do this within an applescript? Thanks so much!

AppleScript Quicktime record on different camera

How do I change the quicktime document current camera to a different camera in AppleScript?
I want the script to automatically switch to my iphone and then record a video.
I have it done so that it's using system events clicks but this way is slow and clunky.
tell application "QuickTime Player"
activate
tell application "System Events"
activate
tell process "QuickTime Player"
click menu item "New Movie Recording" of menu "File" of menu bar 1
set cameras to button 3 of window 1
click cameras
delay 0.5
click menu item 3 of menu 1 of cameras
end tell
end tell
delay 2
tell (document 0)
start
delay 3
stop
end tell
end tell
As per the QuickTime Player scripting library, you can retrieve a list of video recording devices using the command:
get [id, name] of video recording devices
which will return something like:
{{"CC26302Z3U5H0X0FP", "iGlasses"}, {"FaceTime Camera", "iGlasses"}}
corresponding the id and name of each camera, respectively. Each movie recording has a bunch of properties, one of which is called current camera, which is of type video recording device. This property is both readable and settable, in theory.
Therefore, one ought to be to do this:
set R to new movie recording -- creates new recording
set current camera of R to video recording device named "iGlasses"
However, this command does absolutely nothing. Indeed, when I try and read the value of the property, using get current camera of R, it returns missing value.
So, my feeling is that this feature has yet to be implemented properly into AppleScript, or there's a bug in QuickTime Player.
Doing a quick Google now reveals lots of people have encountered this problem and others have come to the same conclusion as I, e.g. here.
Other people's suggestions all seem to resort to GUI scripting, which I share your feelings about.
Sorry this isn't the answer you were hoping for.

Embed external application inside a Cocoa SplitView

I would like to have an application under Mac OS X that enables me to have Sublime Text 2 and a terminal (for showing test result, run grunt tasks and so on) in the same fullscreen window. I couldn't find an application whith this behaviour and I think of reproducing it myself with cocoa split view.
I would like to know if it's possible and, if yes, how can I start implementing it
Thank you
You can't create a new application from 2 other applications. It won't work. However you can use applescript to make it easy for you to position these windows as you want.
As an example I'll use Safari and Terminal as my 2 applications. Open them and place them on the screen as you want them to appear. I opened each window large and positioned them side-by-side. Then I ran this applescript to get their window size and position properties...
tell application "System Events"
tell process "Safari"
set safariSize to size of window 1
set safariPosition to position of window 1
end tell
tell process "Terminal"
set terminalSize to size of window 1
set terminalPosition to position of window 1
end tell
end tell
return {safariSize, safariPosition, terminalSize, terminalPosition}
Then I copy/pasted the result from that script into the "theValues" variable in this script. Now whenever I want I can run this script to recreate those window positions.
set theValues to {{1001, 1025}, {0, 22}, {613, 1024}, {1003, 22}}
tell application "Safari" to activate
tell application "Terminal" to activate
tell application "System Events"
tell process "Safari"
set size of window 1 to item 1 of theValues
set position of window 1 to item 2 of theValues
end tell
tell process "Terminal"
set size of window 1 to item 3 of theValues
set position of window 1 to item 4 of theValues
end tell
end tell
I hope that helps. Good luck.

Set bounds of Screen Sharing window no longer working in Lion

I use my Mac Mini to play movies and music on while working on my MBP. I like to keep screen sharing open but reduced in size in the upper right corner of my screen so that I can effectively have a "PIP". When I want to tag a song that is playing or change the movie, I use a key command to make the window full size, then another key command to shrink it back and position it in the upper right corner.
Since I updated to Lion, I've been getting the following error:
error "Screen Sharing got an error: Can’t set window 1 to {1191, 22,
1441, 185}." number -10006 from window 1
The code is below. Does anyone know what I'm doing wrong?
tell application "Screen Sharing"
activate
set the bounds of the first window to {1191, 22, 1441, 185}
end tell
I have also tried changing the code to use the wording "set the bounds of window 1..." but get the same error.
Any help would be much appreciated.
--Adam
If you look at the applescript dictionary for the application, it doesn't know those commands (e.g.. window or bounds). It only knows the GetURL command so it certainly won't work.
However there is another option. System Events knows about windows and it knows the size and position commands. So you can use that instead...
tell application "System Events"
set ssProcess to first process whose name is "Screen Sharing"
tell ssProcess
tell first window
set position to {0, 20}
set size to {605, 400}
end tell
end tell
end tell
tell application "Screen Sharing" to activate

Resources