Solved

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

Posted on 2015-01-26
3
125 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

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 Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 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