Schedule a terminal command or script file to run daily at a specific time. Mac OS X

I want my computer to set the volume to a certain level every night at 11:45. I am using OS X 10.11.4. I can set the volume manually through the terminal with

osascript -e "set Volume 1.7"

or as a script with

set volume 1.7

I want this to be planned for the night, though. It is hard to find something on the Internet that is not super obsolete. I really don't want to use iCal. From what I found, an online launch is the way to go, but as a noob I don't know where to start.

I see something about using .plist in / Library / LaunchAgents So, I found the elegant plist generator Launched.zerowidth.com, but what code do I add to plist to get the desired effect? I also ask if this is the right way to execute if any user is logged in.

Am I going the wrong way here? I am open to any idea for this to happen, but I do not want a third-party application that I have to keep open all the time.

Thank,

Naboo

+6
source share
3 answers

Note the use of the cron daemon. It is present in osx by default.

create a script to adjust the volume

#!/bin/bash -l
/usr/bin/osascript -e "set Volume 1.7"

Then add a new line to crontab.

crontab -e

vi (m).

export EDITOR=/path/to/your/awesome/editor

crontab

0 20 * * * /path/to/volume/script.sh

8 .

. crontab https://en.wikipedia.org/wiki/Cron

+14

@TheDarkKnight, cron launchd.

launchd, com.example.volume.plist ~/Library/LaunchAgents/:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>com.example.volume</string>
        <key>ProgramArguments</key>
        <array>
                <string>sh</string>
                <string>-c</string>
                <string>set volume 1.7</string>
        </array>
        <key>StartCalendarInterval</key>
        <dict>
                <key>Hour</key>
                <integer>23</integer>
                <key>Minute</key>
                <integer>45</integer>
        </dict>
</dict>
</plist>

launchctl load ~/Library/LaunchAgents/com.example.volume, . launchctl start com.example.volume.

, root, /Library/LaunchDaemons/.

+8

@Miles

.

?

<string>sh</string>
<string>-c</string>

I'm sorry, I'm also trying to schedule a script that includes FTP, and Automator doesn't seem to like FTP. My script (which works fine when I run it from the terminal):

#!/usr/bin/env bash
cd ~//Documents/Apps/mc2xml
ftp <<**
open <mydomain.tld>
cd /public_html/docs
put xmltv.xml
bye
**
echo finished.
# uses ~/.netrc for domain id/pass

thanks james

0
source

All Articles