Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2015-01-26
3
Medium Priority
?
134 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 400 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 1600 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
In this article we have discussed about the OS X EI Capitan and how to fix Wi-Fi issue in OS X El Capitan. We have explained how to delete system level preferences and create a new Wi-Fi location to resolve Wi-Fi issue.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

722 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