DescubreApple

Apple, Mac, iPhone, iPad

Industry

Control some functions of your Mac via emails

Looking for information about scripts, I came across this interesting article from Factormac; I haven’t changed anything in its content since it explains perfectly the steps to follow to control our Mac as well as some applications through the use of emails.

In order to control the Mac via emails, you will first need to prepare the scripts we want to activate and then set up a rule in Mail. Which scripts you want to activate is up to you, but I had planned this for the basics. Shut down the Mac, restart it, put it to sleep, or open/close an application.

    Shut down: tell application “Finder” to shut down
    Restart: tell application “Finder” to restart
    Sleep: tell application “Finder” to sleep
    Open app: tell application “App name” to activate
    Close app: tell application “App name” to quit

If you want, start by creating all these scripts and saving them (File -> Save as…), and we’ll move on to the Mail rules.

OK, let’s open Mail.app, go to the preferences and select at the top where it says “Rules”, click on add rule, and from here it depends a little on each person. I’ll explain the basics and the finer details, like giving them colors, you can do to your own taste. Here are the fields and what to enter:

    – Description: as the name says, this is so you know what the rule is about.
    – In the first dropdown, select “all”, so the script only runs when all the conditions are met.
    – -Subject- -is- ‘System’
    – -Message text- -is- ‘Shut down’
    Perform the following actions:
    – -Run AppleScript- and select where you saved it.


OK, I’m not sure if this has been very clear, so I’ll put up an image just in case.

funcionesmacemails

Now you can create whatever rules you want, both to shut down, and to restart, to open applications and so on.

And now, to clear the palate a bit before moving on to the second one: ‘open links in Safari’. I’ll simply give you the script and see what you can do with it…

    tell application “Safari” to open location “www.factormac.com”

And second, ‘control iTunes via mail‘. I’m sure you can already imagine something after the starter, and yes, the technique will be the same. I suppose you’ve already played around a bit with Mail rules, and if not, what are you waiting for? So I’ll simply explain the iTunes scripts. I will vary the format of the scripts a little, since they will contain more than one command and would be harder to read on a single line.

Open iTunes and play:

    tell application “iTunes”
    activate
    play
    end tell

Stop playback:

    tell application “iTunes”
    stop
    end tell

Previous/Next song:

    tell application “iTunes”
    previous/next track
    end tell

So far so good, but let’s move on to a slightly more complex one, select a playlist and play it.

    tell application “iTunes”
    set the_playlist to user playlist “Playlist name”
    set view of front window to the_playlist
    play the_playlist
    end tell

OK, here I’ll share another little trick: if you want to play the ‘Random Session‘, simply type ‘Random Session’ where the playlist name goes. Now we set up the Mail rules however you want them so that a simple email, from your iPhone for example, changes the song.

Did you like the first and the second one? Then let’s move on to dessert. A script to make the Mac speak.

    tell application “Finder” to say “whatever you want it to say”

If you want it to speak Spanish, you can download a Spanish voice, for example Cepstral, otherwise it will speak English.

This article is one of the best I’ve read about scripts, I hope it will be very useful to them.

Via | Factormac

DA
1 comment · Comment

1 comment

🇬🇧 EN