Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to start a cron job/service on a Mac?

Posted on 2015-01-26
3
118 Views
Last Modified: 2015-02-07
Hello,

I'm trying to write a cron job/service that will start up based on a set of key strokes; and then execute a macro based on a second set of key strokes.

Is it possible to do this in a fairly straightforward way? I'm trying to find out if AppleScript is capable of doing this, since I'm on a Mac; but I'm open to any shell script that will accomplish the same task.

Appreciate any help!
0
Comment
Question by:Errang Genevre
3 Comments
 
LVL 18

Assisted Solution

by:Simon
Simon earned 100 total points
ID: 40573892
Not sure if I can help, but for openers.. which version of OSX?
cron is now deprecated and launchd is the favoured component in Mavericks/Yosemite.

Applescripts can be launched by keyboard shortcuts - configured via the Keyboard preferences pane
http://en.wikipedia.org/wiki/AppleScript

See this nice blog post on launchd and interfaces for it
http://nathangrigg.net/2012/07/schedule-jobs-using-launchd/

What sort of macro are you referring to? Is it an Applescript or a shell script?
0
 

Author Comment

by:Errang Genevre
ID: 40574396
I am using Yosemite.

Yes, I understand the basics of using AppleScript as a service.

What I'm trying to create a script that will:
1) Launch when a combination of keys are pressed. (I have this covered with starting the AppleScript)
2) Perform additional actions when another set of keys are pressed. (Been trying to get this to work)

I'm flexible in implementing this as an AppleScript or a shell script.
0
 
LVL 39

Accepted Solution

by:
Eoin OSullivan earned 400 total points
ID: 40588969
OK .. if the Applescript you create is saved as an APPLICATION .. you can launch it with a keystroke - SimonAdept covered how to do that using the Keyboard Shortcuts in System Preferences.

Once the application is running the code in the AppleScript APPLICATION can be used to emulate the pressing of other keystroke combinations .

This code will press the COMMAND + Q combination
tell application "System Events"
	key down {command}
	keystroke "q"
	key up {command}
end tell

Open in new window

or it can be written in other ways
 tell application "System Events" to keystroke "q" using command down

Open in new window

or
 tell application "System Events" to keystroke "h" using {command down, shift down} end tell

Open in new window


There are a LOT more options to target a specific application which are covered here
http://lifehacker.com/5749811/turn-any-action-into-a-keyboard-shortcut-on-your-mac

Finally if you want the running app to be LISTENING for certain key combinations it gets more complex ..
http://foolsworkshop.com/applescript/2008/05/reacting-to-keyboard-input/
http://macscripter.net/viewtopic.php?pid=114479#p114479

You could also consider using Automator to run any shell script when a key combination is pressed rather than trying to do it all in AppleScript.

The idea of  cronjob is that it runs automatically on a schedule .. if you simply want to execute a shell script on demand .. simply set up Automator or Applescript to run the shell script and assign a key combination.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question