Solved

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

Posted on 2015-01-26
3
120 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
[X]
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
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 40

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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

We could spend the next millennium discussing the differences of the Mac and Windows platforms. The next century will continue to have fanatics on both side of the equation and neither side will win the war. However, that’s not why we are here. W…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

749 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