Hot answers tagged

35

Scripts run via Automator use the default search path which usually does not include /usr/local/bin. In your case an easy fix would be to put export PATH=/usr/local/bin:$PATH somewhere at the beginning of the script.


34

You need to set 'execute' on the file for it to allow you to run it: chmod u+x /path/to/file.command u is the owner of the file, +x adds 'execute', so u+x gives the owner of the file the ability to execute it …then you can run it in the future by double-clicking it.


30

sudo launchctl bootout gui/$(id -u <username>) or sudo launchctl bootout user/$(id -u <username>) Replace username with the target user's user name or replace the whole subshell with the user's uid. This tells launchctl to teardown the users login session (gui specifically refers to the user's temporary login session, user specifies the users ...


29

To log out purely from terminal (or a remote ssh session), just kill the loginwindow process: sudo pkill loginwindow You could get fancy and specify the user if multiple users have a loginwindow process, but this is an easy one shot, no prompt way to end a user's graphical session.


26

Short answer A .command script should do the trick Step-by-step Open TextEdit and create a new file Convert it to plain text by clicking Format > Make Plain Text Add your commands, one per line. For example, you could do: #! /bin/bash cd ~/Desktop mkdir myCoolFolder cd myCoolFolder Run chmod u+x ~/Desktop/myCommandScript.command in your terminal, where ~/...


24

There are two programs that I am aware of which will easily allow you to configure your Mac to send email from the command line. I have written up HOWTOs for both of them: mailsend msmtp Of the two, I suggest msmtp. Configuration is complicated enough that I'm not sure if I should replicate all of the steps here, but I will mention that if you use ...


24

SleepWatcher may be of use. From the description: It can be used to execute a Unix command when the Mac or the display of the Mac goes to sleep mode or wakes up, after a given time without user interaction or when the user resumes activity after a break or when the power supply of a Mac notebook is attached or detached. It also can send the Mac to sleep ...


24

tell application "System Preferences" reveal anchor "keyboardTab" of pane "com.apple.preference.keyboard" end tell tell application "System Events" to tell process "System Preferences" click checkbox 1 of tab group 1 of window 1 end tell quit application "System Preferences" You could also use defaults write -g com.apple.keyboard.fnState -bool true, ...


23

In Mac OS X Lion the user crontabs are stored in /var/at/tabs. In the past they were located in /var/cron/tabs. You should use crontab -e to interact with these in general, but knowing the location is useful for when you want to restore them from a backup of your disk, or something similar.


23

If you use bash, add the alias commands to ~/.bashrc and save a file like this as ~/.bash_profile: . ~/.bashrc When bash is invoked as an interactive non-login shell, it reads .bashrc but not .bash_profile. When bash is it is invoked as an interactive login shell, it reads .bash_profile but not .bashrc. Terminal and iTerm open new shells as login shells ...


21

Well, here you go with an AppleScript for that. First, create the AppleScript: Open Automator Create a Quick Action Set the input to no input Drag and Drop the Run AppleScript workflow element onto the grey space. Paste the code from below into the AppleScript Save the workflow as Create new file If you have iCloud Drive activated, make sure you are saving ...


18

With the benefit of several years of hindsight: user588's answer and koiyu's answer work well, but they rely on utilities (Rez, DeRez, and SetFile) that: aren't installed by default (they come with either Xcode or the developer command-line utilities) are now deprecated (Rez and DeRez, because they relate to Carbon) osxiconutils look interesting, but won'...


18

This is very easy to do. For efficiency (and cool factor), I would use a tool like Lingon to launch this script periodically using launchctl/launchd instead of each time you start a shell. On my MacBook, it takes 3 seconds to update the second time (no work done, DNS cache set, etc...) and it take 10 second to run the first time (no work done) or 15+ ...


17

It appears that as the OS ships, sleep/wake cannot trigger scripts, but third party solutions have been developed. Scenario appears to be one such solution. Power Manager also seems to add some script triggering abilities. I can see it can trigger scripts on wake from sleep and it can trigger scripts on sleep. I have no personal experience with these ...


17

As patrix has pointed out in a comment, you can set up any Mac to start up or wake up, and sleep or shut down at specific times, via the System Preferences -> Energy Saver -> Schedule... settings. You could also try using AppleScript, e.g. this code (edit it with Script Editor, then save as an Application): tell application id "com.apple.systemevents" -- ...


17

All processes get paused when the system goes to sleep, independent of whether the process is part of macOS, an application or some code you wrote on your own. After the system wakes up again, all processes will continue to run.


17

There is a very well documented open source script that reads the software update catalogs and parses them for the major macOS installer components, prompts you which build and version to download and will then commence to download each portion to your filesystem and then build an installer application or image based on the options you choose. https://...


16

This has worked for me in the past: Log out (with confirmation) osascript -e 'tell app "System Events" to log out' Log out directly (no confirmation) osascript -e 'tell app "System Events" to «event aevtrlgo»' or osascript -e 'tell application "loginwindow" to «event aevtrlgo»' This way any running application will get noticed and can terminate in a ...


15

The most basic way to send mail is trough a telnet session with the smtp server of your provider/network. After you contacted the server and after every command the server will answer if it accepts the command with something like "250 OK", or if not with an error message. All details can be found in RFC2821 - Simple Mail Transfer Protocol, Google for it. ...


15

Take the script that you created: #!/bin/bash echo "plugin L2TP.ppp">>/etc/ppp/options echo "l2tpnoipsec">>/etc/ppp/options Save it in your home directory, or a 'scripts' directory inside your home directory, as l2tp.sh. Allow it to be executed(write this command in Terminal): chmod 700 ~/path/to/l2tp.sh To execute the file using sudo (root ...


15

The following works: osascript -e 'display notification "Hello world!" with title "Hi!"'


14

I'm assuming that you'd like to initiate this procedure as opposed to having it run at a regularly scheduled time. My approach would be to initiate this from the command line, but any commands can be run in a shell script component of an Automator script with some modification. The following approach combines a few components to get the job done: A tell ...


14

There is no native alternative. You must acquire watch from using Homebrew (brew install watch) or MacPorts (port install watch) if you require an actual executable. You can however, emulate the function of watch. That can be accomplished in a standard bash while loop (from Stack Overflow by Daniel Pittman): You can emulate the basic functionality with ...


13

I'm stumped as to why cp is behaving this way if there's no alias involved. However, there is a quick-dirty-and-dangerous utility provided for this exact situation: yes. You can use it to pipe a continuous stream of affirmatives into any command that gives you confirmation prompts (you can use it to send any text, but the default is "y"). yes | cp foo bar ...


13

You can use pmset to do this and it will be a "once and done" solution. Once you issue the pmset command, it will shutdown/startup/wake on the schedule you set; you won't have to create a script that runs at a predetermined time each time. pmset uses this format: pmset schedule day/date time Here are a few examples: pmset repeat sleep MTWRF 23:30:00 puts ...


12

This worked for me, it was written with Lion in mind but works for Mountain Lion. Btw this is using Gmail so if you're not... You don't need to download anything! (just setup a gmail account) http://www.anujgakhar.com/2011/12/09/using-macosx-lion-command-line-mail-with-gmail-as-smtp/ Configure Postfix for Gmail SMTP Edit file /etc/postfix/main.cf sudo ...


12

Check out cocoaDialog: cocoaDialog is an OS X application that allows the use of common GUI controls such as file selectors, text input, progress bars, yes/no confirmations and more with a command-line application. It requires no knowledge of Cocoa, and is ideal for use in shell and Perl scripts (or Ruby, or Python, or... etc). It's a pretty simple ...


11

This is my own app, so consider that, but ControlPlane has the ability to do actions based on Sleep/Wake. You'll find it at http://www.controlplaneapp.com/. ControlPlane is a fork of MarcoPolo and has been updated to run on Snow Leopard and Lion.


11

When passing input to Run Shell Script in Automator you need to change Pass input: to stdin to Pass input: as arguments as shown in the example workflow below.


Only top voted, non community-wiki answers of a minimum length are eligible