Quantcast
Channel: The Square Media Blog » Xavier Serrano
Viewing all articles
Browse latest Browse all 10

How to build a J.A.R.V.I.S boot up automator script?

$
0
0

I previously made a tutorial on How to build a J.A.R.V.I.S alarm using applescript? Inspired by the first Iron Man movie scene with the J.A.R.V.I.S. morning wake up alarm, Now, Ill show you how to creat an automator app that will run some checks and launch some apps when your computer starts. If you happen to use Geek Tool this is a good way to have your geeklets launch as if J.A.R.V.I.S. were running inside your Mac. Here is a video i posted on my page showcasing the Boot Up sequence, the video also includes the alarm I previously created a tutorial for here.

First, a few things you'll need for my complete script:

  • Automator.app
  • audio files with the JARVIS voice, or something else of your choosing.

Let's get down to coding. throughout the whole script try to read the script as I've provided comments and put the things you need to change like this --something--. Also it doesn't hurt to know what is going on.

First, Open up Automator.app and create a new application. Then choose the Run Applescript action. Now, you can start typing the code in right after the (* Your script goes here *) line.

This is the script you use when you want to run an audio file on the background as the rest of your script keeps going. This doesn't stop the script until the song is done playing.

do shell script "afplay '--path to file--' > /dev/null 2>&1 &"

Here we are making sure that the wi-fi is on, and if its not turn it on. Once its one we connect it to our preferred wifi network. Finnaly we change the network location if we have connected to our preferred wifi network. I do this as i assume that if it connects to my network it means I'm home. I use a very specific network configuration when I am Home, so that i can share my keyboard and mouse using Teleport application. If you choose to you guys can omit this step.

set makiaeawirelessstatus to (do shell script "networksetup -getairportpower en1")
  
  if makiaeawirelessstatus is "Wi-Fi Power (en1): Off" then
    (do shell script "networksetup -setairportpower en1 on")
    --say "Powering WiFi On"
    delay 5
    set theWiFi to (do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}'")
    if theWiFi does not contain "SSID" then
      --say "Connected to wifi " & theWiFi
    else
      --say "Atempting to connect to --network name--"
      try
        do shell script "networksetup -setairportnetwork en1 '--network name--' '--network password--'"
        delay 5
        set theWiFi to (do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}'")
      on error
        --say "Couldn't connect to --network name--"
      end try
    end if
  else if makiaeawirelessstatus is "Wi-Fi Power (en1): On" then
    set theWiFi to (do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}'")
    if theWiFi does not contain "SSID" then
      --say "Connected to wifi " & theWiFi
    else
      --say "Atempting to connect to --network name--"
      try
        do shell script "networksetup -setairportnetwork en1 '--network name--' '--network password--'"
        delay 5
        set theWiFi to (do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}'")
      on error
        --say "Couldn't connect to The G33k Network"
      end try
    end if
  else
    --say "couldn't check wifi state"
  end if
  tell application "System Events"
    tell network preferences
      -- get the current network lcoation
      set activeLocation to the name of current location
    end tell
  end tell
  if theWiFi is "--network name--" then
    if activeLocation is "--network location name--" then
      --say "Connected to --network location name-- network location"
    else
      do shell script "scselect '" & ("--network location name--") & "'"
      --say "Changed network location to --network location name--"
    end if
  else
    do shell script "scselect '" & ("Automatic") & "'"
    --say "Changed network location to Automatic"
  end if

Now, we are going to create a list of all the applications we want to launch when we boot up or login into the account. This way you only need to set up one application to load. For geek tool is tricky but the good thing is by doing this the audio will be more in sync with the launching of applications. Also my boot up is a lot faster as this scripts acts as if you were opening the apps after boot up. Keep in mind i have commented out the say applescript command but if you would like to have it just take the -- off and change what the script says if you'd like to.

--say "Launching required applications"
  
  set appList to {"Mint QuickView", "iAntiVirus", "Dropbox", "Google Drive", "FreeMemory Pro", "GeekTool Helper", "EventScripts"}
  repeat with thisApplication in the appList
    try
      if thisApplication contains "GeekTool Helper" then
        log "inside"
        
        set posixCalculatorPath to "/Applications/GeekTool.app/Contents/PlugIns/GeekTool.prefPane/Contents/Resources/GeekTool Helper.app"
        tell application posixCalculatorPath to activate
      else
        tell application thisApplication to launch
      end if
      --say thisApplication
    end try
  end repeat
  do shell script "afplay '--path to file--' > /dev/null 2>&1 &"
  --say "I have indeed been uploaded, Sir. We are online and ready! At your service, Sir! 
  quit

Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images