Menu

Scripting Challenge Response: How I create my own window layouts.

For the summary of the scripts, jump to 13:34 This is a response to a scripting challenge. (For Rohit!) Sorry it took so long. It's a bit haphazard, but I wanted to show you the full process of what it's like to make a script. It's usually not smooth like I present in my videos, but it shows the real process. Window management app I use: https://www.irradiatedsoftware.com/sizeup/ For this video, I assume you've watched this video: https://prodshop.co/how-i-automate-my-job and downloaded these shortcuts: https://prodshop.co/automate-with-applescript Also, I'm using Atom to code AppleScript. To install the proper plugins, watch this video: https://prodshop.co/applescript-with-alfred to get the Atom plugins. Here are the scripts I created in the video and also used: https://prodshop.co/window-scripts Sorry if this was confusing, If you need more help, let me know! Music by https://cordio.bandcamp.com/
Transcript

hey what's up this is a video to respond to the scripting challenge on how to make different configurations of different apps in different positions i'm gonna do it two ways one if you're using sizeof which is a window management tool i love it it's only 12 bucks or there's a demo and then two the manual way let's get started size up first so i have a couple applications open i have google chrome the finder and script editor so what i want to do is go ahead and set a configuration for size up to have script editor in the bottom left finder in the top top left and the half screen of google chrome on the right so what i'm going to do is i'm going to do new apple scripts i'll include the apple script shortcuts from my how i automate my job with the text expansion shortcuts watch a video on that but i'm just going to go through with this example so this would be called configuration config one okay so i'm going to go ahead and start writing my code okay so first we want the finder to activate and then we want to do size up top left so i'll do center window and then do action top left so i'm going to go ahead and run config one and see if it works okay it didn't work i might have done it wrong yeah so it's upper left so i'll change it to upper perfect so now i'm gonna do the other ones okay tele script editor to do action let's see lower left and then tella google chrome i'm gonna put it over here to do action right okay so let's say i had all of these hidden i'm gonna hide this and i'll go ahead and do command space config one there we go let's go ahead and change the arrangement but we're going to use the manual way so i'm going to go ahead and do a second configuration manually and i'm going to put brave browser and google chrome in the second configuration and i'm going to use this apple script which will read the coordinates of the window of the front most app and then later we can program those coordinates to move the windows how we want them i'll show you what i mean okay so the script basically says tell the front application and i'll do brave browser to activate and it's going to read the coordinates and spit them out here okay so i'm going to just do command r i'm going to go ahead and go to atom i'll make a new script config 2 and i'm just going to save the coordinates okay so that's the brave browser let's say we want atom to be here exactly here so i'm going to change this to adam and run it there are the coordinates for adam then i'm going to do google chrome and i want it to be right here this isn't an optimal window layout but just to show you and illustrate it okay so i'm going to change this to google chrome run it okay so here's my google chrome okay there's probably other apps that can do this in a different way but i like this way it's cool it's free ish um yeah it's free okay so now instead of get window position we're gonna set window position so set window okay so this is another script and i'll provide it yeah so basically it says set the app to the bounds okay so i'm gonna copy this i'm gonna hide script editor and go to atom so i'm gonna paste it three times okay and then i'm gonna go ahead and delete this part actually let me start over i'm gonna delete this and i'm gonna copy this three times and then for the variable front app i'm just gonna change it to the app that we want so okay the first one was brave so brave browser i'm going to go to the next front out and instead of using the mouse or clicking i'm just going to search for front app and atom and then i'm going to type i'll push escape and then i'll do atom and then the last one is google chrome all right now i'm going to just copy our coordinates that we took from the other script and put them inside of the corresponding applications now another cool thing that might be good to do is to i'm sure there's a way you can do it in terminal but basically you can hide all windows hide all hide hide all windows and then do your configuration that might be cool let me just look it up how to do it okay so the terminal command is i can't find it but basically what you can do is um open sys open the system events and you can do keycode 49 with command down gonna test that out actually it's using command down and then type hide all windows text loop hide all windows okay so let's see if that works you'll have to go to alfred or basically just type hide and make sure that hide is the first one if this doesn't make sense i'm sorry but basically i'm just automating doing command space and doing high so i'll do config two okay and then i'll push enter okay so basically we'll hide all the windows by doing command space i'll send you this code too you have to have alfred um but okay let's keep going okay just gonna back up a little bit there we go cool okay now we'll finish copying our coordinates so adam will be here and we'll go to adam now you may be now you may be thinking this is a lot of work it is it's a lot of work but how many times are you manually arranging those windows over a year so if you take a little time and set it up you can have a great setup okay so i'm going to go ahead and save it all right so let's go ahead i'll take the code to hide windows and i'll put it inside of our first configuration boom okay this script has excited me for some reason okay let's go ahead and do command space let me put alfred in the middle no let's find it okay command space config one did not work let's see oh i forgot this okay config one hide okay so the finder's not coming up let's do we'll do command n for a new window okay let's see if that works okay all right config one cool so we got finder script editor google chrome bam now let's do config 2. did not work i forgot one piece of code let's try it again so one config one okay so i'm gonna go ahead and do okay try one more time you may be wondering why i'm not editing out all these parts that aren't working but i'm just trying to show you how it works and to keep going if it doesn't work but i'll send you the scripts and stuff okay so config 2 is not working okay what's going on okay so whenever there's an error and i'm editing it's in atom i like to go to script editor and do save and it'll tell me the error let me just try that got it figured it out we have to tell the we have to tell each application to activate first so tele brave browser to activate then to move the window got it okay that should work all right so config let me go ahead and fix config one so yeah config one is good okay so config two hide all windows bring it up that was our position we'll do config one hide all windows boom let's go back to config two let's try that one more time config one cool config too okay so script editor is hanging out okay config one config two cool so if you have any questions you can email me at hello with the productivityshop.co or join the slack channel um sorry if this was kind of a random video quick note and i'll put up with the scripts and the link to the summary if you don't want to watch the how i did it okay okay so here's the summary install size up and then write the code like this tele whichever app you want to activate and then do center window and then go to the size up icon in the menu bar and choose which position you want it lower left lower right so if i want to do lower left okay and then put this into the applescript template which i'll send you and you'll be good and just copy and paste and you can change the title of the app and the position if you have sizeof installed okay if you want to do it manually using the get window position script and the set window position open the get window position script choose which app you want to read the coordinates open the script in script editor so change this to the app you want to get the position for run it it'll get the position and then in your apple script you can use this code so if you want google chrome to come to these coordinates copy the coordinates paste them in the position script change this to google chrome and don't forget to activate the program you want to move and might not include the summary but okay so i'm going to run the position script that i made so i'll run the script and then it works so basically use the get window position find out the coordinates and put it in the window position script and activate each program before you set the coordinates for the desired program cool hope that helped later

The Productivity Shop, LLC / Trademark 2020