Solved

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

Posted on 2015-01-26
3
114 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:SimonAdept
SimonAdept earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
The /etc/authorization file in Mac OS X 10.x can be used to control access to the various panes of the System Preferences amongst other things. It’s used by some of us Mac Sys Admin’s to give Standard Users access to System Prefs panes that only adm…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now