<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Karolinkas</title>
    <description>The latest articles on Forem by Karolinkas (@karolinkas).</description>
    <link>https://forem.com/karolinkas</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F557055%2Fd13e2b0f-d38c-4936-8d2f-4b2d1b9669b8.png</url>
      <title>Forem: Karolinkas</title>
      <link>https://forem.com/karolinkas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/karolinkas"/>
    <language>en</language>
    <item>
      <title>A small Tutorial for GraphQL Pagination with MongoDB</title>
      <dc:creator>Karolinkas</dc:creator>
      <pubDate>Mon, 18 Jan 2021 09:18:49 +0000</pubDate>
      <link>https://forem.com/karolinkas/a-small-tutorial-for-graphql-pagination-with-mongodb-gkh</link>
      <guid>https://forem.com/karolinkas/a-small-tutorial-for-graphql-pagination-with-mongodb-gkh</guid>
      <description>&lt;h3&gt;
  
  
  Why is GraphQL so great?
&lt;/h3&gt;

&lt;p&gt;Developers that are regularily writing API endpoints are pretty excited about GraphQL since it came out in 2015. But what's so special about it? Basically it gives you more freedom as a developer to request only exactly as much data you really need, it's aiding type safety and allows your API to evolve without versioning. GraphQL is actually it's own language for querying databases that is very much worth it to look into because it might make API development more smooth like this guy, almost like this guy:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fy0008jctapwr6dqrbjwd.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fy0008jctapwr6dqrbjwd.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Is this for me?
&lt;/h3&gt;

&lt;p&gt;If you have never tried out GraphQL with MongoDB, but you are super curious about it, don't despair, but try this tutorial before, that explains you how to bring together GraphQL with MongoDB: &lt;a href="https://medium.com/the-ideal-system/graphql-and-mongodb-a-quick-example-34643e637e49" rel="noopener noreferrer"&gt;https://medium.com/the-ideal-system/graphql-and-mongodb-a-quick-example-34643e637e49&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What pagination means here
&lt;/h3&gt;

&lt;p&gt;First of all let's confirm we agree on what pagination means for us. Pagination according to our understanding could for example give the user of a web application the chance to customize how much of the search results of list he wants to see. If there's a lot of details he would prefer to see 10 results in a list rather than 100.&lt;/p&gt;

&lt;p&gt;Now let's jump into the actual tutorial:&lt;/p&gt;

&lt;h3&gt;
  
  
  Tutorial
&lt;/h3&gt;

&lt;p&gt;👉 &lt;strong&gt;Tip&lt;/strong&gt;:&lt;br&gt;
This assumes you have mongoDB installed locally, if you realise you don't, this is a good guide: &lt;a href="https://docs.mongodb.com/manual/administration/install-community/" rel="noopener noreferrer"&gt;https://docs.mongodb.com/manual/administration/install-community/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Clone my repository with the example project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;git clone git@github.com:karolinkas/graphQL-pagination.git
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run &lt;code&gt;yarn&lt;/code&gt; to install all dependencies. &lt;/p&gt;

&lt;p&gt;Make sure you local mongo instance is running, if not start it with the mongo daemon&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mongod
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;To illustrate you how and where we might be needing pagination I created a graphql server that connects to a local mongo db instance.&lt;/p&gt;

&lt;h3&gt;
  
  
  The mineral collection as an example
&lt;/h3&gt;

&lt;p&gt;Imagine you are really obsessed with minerals and would like to have digital representation of your collection. Using graphQL queries you will be creating minerals that have a &lt;code&gt;name&lt;/code&gt; and a &lt;code&gt;content&lt;/code&gt;&lt;br&gt;
( with important containing chemical elements ) property each time you add a new one to your collection.&lt;/p&gt;

&lt;p&gt;To see the project in action get things ready by running&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;which builds and starts an express server.&lt;/p&gt;

&lt;p&gt;Open &lt;a href="http://localhost:3001/graphiql" rel="noopener noreferrer"&gt;http://localhost:3001/graphiql&lt;/a&gt;&lt;br&gt;
GraphiQL is an online IDE (editor) that allows you to run queries and mutations against your database.&lt;/p&gt;

&lt;h3&gt;
  
  
  Making minerals
&lt;/h3&gt;

&lt;p&gt;To create a mineral ( a database entry ) in our mineral collection run this in GraphiQL. :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mutation {
  createMineral(name: "Quartz", content: "Silicon"){
    _id
        name
        content
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Create a bunch of them with different mineral names to have a good list of example minerals.&lt;/p&gt;

&lt;h3&gt;
  
  
  Exploring minerals
&lt;/h3&gt;

&lt;p&gt;To see and explore what minerals we already created run in GraphiQL:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;query {
  minerals {
    _id
    name
    content
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You'll see that this query returns the list of all the minerals that you ever created, but what if you have a huge collection of 250 minerals and you don't want to show the all in a giant list.&lt;br&gt;
That's where pagination comes into play.&lt;/p&gt;

&lt;p&gt;An example for this would be to limit the query's return value to 4 minerals instead of showing all 12 at once. If we are showing only the minerals in the second row there is an offset of 4 minerals. We could leave the decision how many results should be shown at a time to the user, by presenting some UI that lets the user pick from some options that then set the &lt;code&gt;limit&lt;/code&gt; parameter.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzzs6aum64p23k34zrd34.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzzs6aum64p23k34zrd34.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Adjusting Query
&lt;/h3&gt;

&lt;p&gt;Let's try to implement this with a graphql query.&lt;br&gt;
In src/start.js you will be able to find the definition of query and it's types.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Query {
    minerals: [Mineral]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If we want to give the user new functionality we could just add new parameters to the query.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Query {
    minerals(limit: Int, offset: Int): [Mineral]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then in the resolver, which is what brings together the mongodDB Query and the GraphQL query,&lt;br&gt;
this resolver:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Query: {
    minerals: async () =&amp;gt; {
        return (await Minerals.find({})
            .toArray()).map(prepare)
    },
},
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;turns into&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Query: {
    minerals: async (root, {limit, offset}) =&amp;gt; {
        return (await Minerals.find({})
            .limit(parseInt(limit))
            .skip(parseInt(offset))
            .toArray()).map(prepare)
    },
},
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here we are using the parameters that we defined in the Query type to limit/offset the results the query will return.&lt;/p&gt;

&lt;p&gt;Now when trying out the new pagination functionality we set the new parameters in GraphiQL, to implement the same pagination like in the infographic we would do:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;query {
    minerals(limit: 4, offset: 4) {
        _id
        name
        content
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;On the other hand the limit/offset pagination comes with a couple of disadvantages, i.e. if one mineral gets removed the whole mineral collection gets shifted forward, which might change the query's response in unexpected ways. That's where cursor-based pagination might bring more specific results. The idea of cursor pased pagination is that we create references to each object, in this case mineral, where the user might have left off while exploring all minerals. From this reference point we can then fetch more data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1q0e6ocula12th47o66k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1q0e6ocula12th47o66k.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's implement this with GraphQL, we'll still need the limit of results to show but will know pass in a cursor, which to simplify things for the sake of this tutorial will be the index of the mineral that's currenlty being looked at by the user. This is the type:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Query {
    minerals(limit: Int, index: Int): [Mineral]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And the query will now be:&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Query: {&lt;br&gt;
    minerals: async (root, {limit, index) =&amp;gt; {&lt;br&gt;
        return (await Minerals.find({})&lt;br&gt;
            .limit(parseInt(limit))&lt;br&gt;
            .skip(parseInt(index))&lt;br&gt;
            .toArray()).map(prepare)&lt;br&gt;
    },&lt;br&gt;
},&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Next Steps&lt;br&gt;
&lt;/h3&gt;

&lt;p&gt;This implementation could be improved in the next steps, i.e. we could use the id of the mineral to access the right mineral instead of the index to make sure the selection of one mineral is more specific. Also we could add a &lt;code&gt;pageInfo&lt;/code&gt; field to each mineral to store information about the &lt;code&gt;startCursor&lt;/code&gt; and &lt;code&gt;endCursor&lt;/code&gt; assuming the limit hasn't changed and the &lt;code&gt;nextPage&lt;/code&gt; boolean that will allow you to be aware if there's more results to follow.&lt;/p&gt;

</description>
      <category>graphql</category>
      <category>mongodb</category>
      <category>pagination</category>
    </item>
    <item>
      <title>Automate with AppleScript or how to be less distracted
</title>
      <dc:creator>Karolinkas</dc:creator>
      <pubDate>Sun, 17 Jan 2021 20:12:00 +0000</pubDate>
      <link>https://forem.com/karolinkas/automate-with-applescript-or-how-to-be-less-distracted-n97</link>
      <guid>https://forem.com/karolinkas/automate-with-applescript-or-how-to-be-less-distracted-n97</guid>
      <description>&lt;h1&gt;
  
  
  Write some simple AppleScript commands to prevent yourself from procrastinating
&lt;/h1&gt;




&lt;p&gt;A while ago I went on a flight from Spain to the UK for a work meeting and since I was officially on a work trip I decided to try to get some work done throughout the flight and made sure I had the materials I need beforehand. Getting on the flight I ordered a cup of coffee and got started. A couple of times I was about to type something unrelated in the browser, when I remembered that I was on a flight and offline, so I went back to work. The flight passed extraordinarily quickly and I suddenly had reached already in the UK. Surprised I realised at arrival that I had finished the task and even learned a lot because I had time to experiment more. I assumed that this had happened because I was less distracted from being able to search things online that then lead me to other topics that are exciting and, in short, distracted me completely. I think it's absolutely amazing to find ways to work more focussed and have more time for real life. 👪 🏕️ 🍺&lt;/p&gt;



&lt;h3&gt;
  
  
  What do you need for this tutorial?
&lt;/h3&gt;

&lt;p&gt;Especially if you are a new starter it is nice to work with languages that are already installed on your computer, so you can get started without any setup.&lt;br&gt;&lt;br&gt;
Being on a Macintosh, Bash and AppleScript will automatically be installed. If you don't know what these are here or get stuck on the way, that's fine. You can read up here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ryanstutorials.net/bash-scripting-tutorial/bash-script.php"&gt;What is Bash Script?&lt;/a&gt; &lt;br&gt;
&lt;a href="http://downloads.techbarrack.com/books/programming/AppleScript/website/index.html"&gt;Basics of AppleScript&lt;/a&gt; &lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  What do we want to achieve?
&lt;/h3&gt;

&lt;p&gt;Sometimes there is repetitive tasks on your machine that we can simplify by using a script. In this case it would be: turning off distractions temporarily, open your favourite app and set it to full screen mode. &lt;br&gt;
We are using AppleScript for this example, because it's nice and human-readable and great to get started with and lets you easily execute bash scripts, too. It's great to &lt;a href="https://www.urbandictionary.com/define.php?term=macgyvering"&gt;macgyver&lt;/a&gt; a script together fast and get excited about how easy you can interact with your machine, automate things and fine tune it over time. &lt;br&gt;
&lt;br&gt;&lt;br&gt;
&lt;a href="https://i.giphy.com/media/l1LbVMDoxzzedwRVe/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/l1LbVMDoxzzedwRVe/giphy.gif" width="100%"&gt;&lt;/a&gt;&lt;/p&gt;
The fun of writing your own automation scripts


&lt;h3&gt;
  
  
  Starting with your script
&lt;/h3&gt;

&lt;p&gt;Create a file in any code editor called "focus.applescript" and add the below content. &lt;code&gt;do shell script&lt;/code&gt; is the AppleScript command to run a built in bash script. In your terminal then run &lt;code&gt;osascript focus.applescript&lt;/code&gt;, being in the folder where the script is located, to execute the command. The first line informs the application that runs the script, here the Terminal, to use AppleScript. &lt;br&gt;
&lt;br&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;!/usr/bin/osascript

do shell script "networksetup -setairportpower en0 off"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;br&gt;&lt;br&gt;
You will see it does something simple, which is disabling your Wifi. You can confirm in the menu bar easily, because of the greyed out icon. &lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--udvK4QAz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/fp0slg8i3qcl2gh2sg41.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--udvK4QAz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/fp0slg8i3qcl2gh2sg41.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;For sure you can just turn it back on manually, but for the sake of this tutorial it is great because the functionality of the script can be confirmed easily. Now let's get more playful and add a delay until we turn the wifi back on after 30 seconds. &lt;/p&gt;

&lt;p&gt;&lt;br&gt;
&lt;strong&gt;Quick Tip:&lt;/strong&gt; &lt;br&gt;
You can add inline comments with &lt;code&gt;--&lt;/code&gt; in AppleScript and with &lt;code&gt;(* do some magic 💥 *)&lt;/code&gt; for block comments. This is very useful to add explanations to your code for when you later look through it to understand what each part is for. &lt;br&gt;
&lt;br&gt;
&lt;br&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-- Turn off wifi
do shell script "networksetup -setairportpower en0 off"

-- Wait a bit ⏱️
delay 30

-- Turn wifi back on
do shell script "networksetup -setairportpower en1 on"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;h3&gt;
  
  
  Adding an argument
&lt;/h3&gt;

&lt;p&gt;That works as expected, now let's use an argument. We want &lt;br&gt;
to specify how many minutes the WIFI should be turned off. Change your script to the code example below. Then we add the argument to the terminal command to execute the script like this: &lt;code&gt;osacript focus.applescript 1&lt;/code&gt; in combination with the code example below. The argument from the user (here you) gets taken from your command by accessing &lt;code&gt;argv&lt;/code&gt;, it stands for argument values, with which by default gets the first argument. As soon as you introduce a parameter, you have to wrap the previous commands in a "parametrised handler". It's this part &lt;code&gt;on run argv&lt;/code&gt; and &lt;code&gt;end run&lt;/code&gt;, that belong together and in between is the function body, the things you want to happen once the parameter is available. The "parametrised handler" gets called by default when running the script. We can use a variable called &lt;code&gt;secondsOfSilence&lt;/code&gt; to calculate the seconds for the delay using the parameter. That is necessary because AppleScript calculates things related to time in seconds, but we want to to say: "Turn off my internet for 10 mins" and not: "Turn off my internet for 600 seconds". Here is the next example code:&lt;br&gt;
&lt;br&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
on run argv
    -- Now store time required to focus as seconds
    set secondsOfSilence to 60 * argv
    do shell script "networksetup -setairportpower en1 off"
    delay secondsOfSilence
    do shell script "networksetup -setairportpower en1 on"
end run

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;p&gt;&lt;br&gt;
&lt;strong&gt;Quick Tip:&lt;/strong&gt; &lt;br&gt;
When you are unsure about the value of something and you need to double check while developing it can be really useful to add a line like &lt;code&gt;say "The value of" &amp;amp; secondsOfSilence&lt;/code&gt;. You machine will read out aloud what the value is. &lt;br&gt;
&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Adding more arguments to the script
&lt;/h3&gt;

&lt;p&gt;Next let's add a  section to our command to open a specific app that we usually work with and would like to focus on. This one is interesting because as soon as we send a second argument the &lt;code&gt;argv&lt;/code&gt; is a list of values that we need to access differently. With &lt;code&gt;item n of argv&lt;/code&gt; we get each element in the list of arguments and in our case we store it in a variable again. &lt;code&gt;tell&lt;/code&gt; is a built in command from AppleScript to execute things which is wrapped around whatever you would like to do, in this case &lt;code&gt;activate&lt;/code&gt; and launch an app and bring it to front and ends with a closing tag like &lt;code&gt;end tell&lt;/code&gt;.&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    set yourFavouriteApp to item 2 of argv

    -- Open an app you would like to work with and focus on
    tell application yourFavouriteApp

            activate

    end tell
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;br&gt;&lt;br&gt;
Now when trying out the script in the Terminal you will be able to specify another argument, that you can provide like this: &lt;code&gt;osascript focus.applescript 1 "TextEdit"&lt;/code&gt;. Here "TextEdit" is just an example it can be any app you like to work with. The exact spelling matters, it should be the same like the name of the app in the dock.&lt;/p&gt;
&lt;h3&gt;
  
  
  Change settings of a currently running app
&lt;/h3&gt;

&lt;p&gt;Lastly we add a final step, which is setting your favourite app to fullscreen mode. You will see that you can easily nest the &lt;code&gt;tell&lt;/code&gt; commands. After activating the app we add a delay of 3 seconds to give it time to start up and then use the internal "System Events" application that manages processes in your machine to find the app of interest and the its attribute "AXFullScreen" to true. &lt;/p&gt;

&lt;p&gt;&lt;br&gt;
&lt;strong&gt;Quick Tip&lt;/strong&gt;: In AppleScript you can list most available apps with: &lt;code&gt;tell application "System Events" to get name of (processes where background only is false)&lt;/code&gt;.&lt;br&gt;
&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
    -- Open an app you would like to work with and focus on
    tell application yourFavouriteApp

            activate

            delay 3

            tell application "System Events" to tell process yourFavouriteApp

                    -- Set app of interest to fullscreen
                    set value of attribute "AXFullScreen" of window 1 to true

            end tell

    end tell
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;br&gt;&lt;br&gt;
Let's summarise again the steps we took:&lt;br&gt;
&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9EYWxXFt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/t8gbb8k4codqs9i3w7vw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9EYWxXFt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/t8gbb8k4codqs9i3w7vw.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
This is the final script below. Feel free to comment or ask any questions. &lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/osascript

on run argv

    set minutes to item 1 of argv
    set yourFavouriteApp to item 2 of argv

    -- Turn off wifi
    set secondsOfSilence to 60 * minutes
    do shell script "networksetup -setairportpower en0 off"

    -- Open App
    tell application yourFavouriteApp

            activate

            delay 3

            tell application "System Events" to tell process yourFavouriteApp

                    -- Set App of interest to fullscreen
                    set value of attribute "AXFullScreen" of window 1 to true

            end tell

    end tell

    -- After waiting turn wifi back on
    delay secondsOfSilence
    do shell script "networksetup -setairportpower en1 on"

end run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;br&gt;&lt;br&gt;
Now take a well-deserved rest and be proud of your work! Congratulations for having written your own custom command. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/5xtDarqlsEW6F7F14Fq/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/5xtDarqlsEW6F7F14Fq/giphy.gif" width="100%"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>bash</category>
      <category>applescript</category>
      <category>automation</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
