Lowfokus
Posts Tagged osx
Cron Jobs on OS X
Posted by technohermit in Apple, OS X Shell, Uncategorized, Unix on 2009/11/15
Since OS X Tiger, cron has been replaced by a utility called launchd, and three separate launch daemons. Rather than having to run crontab to manipulate scripts, they are run by launchd according to three separate directories inside of /etc/periodic.
The scripts contained in these folders are run at specified intervals by three preference files, in XML format, found in the /System/Library/LaunchDaemons folder. You can manipulate the .plist files with a text editor or Apple’s Property List Editor (if you’ve installed Developer Tools.) They are named, simply enough, com.apple.periodic-daily.plist, com.apple.periodic-weekly.plist, andcom.apple.periodic-monthly.plist. They are, by default, set to run at the same time as the old cron jobs, in the middle of the night. If you happen to shut down your Mac, it might be a good idea to change these intervals to a time when you’re sure the computer will not be shut down, as these jobs are important.
You will find a script in each of these folders called 999.local. This file is set to read-ony by default, and is for ”backwards compatibility with the old /etc/daily.local” according to the comments in the file. (I’m running Snow Leopard.) I’d recommend not modifying the scripts in the /etc/periodic folders, and creating a /etc/daily.local, /etc/weekly.local, and /etc/monthly.local file for your cron jobs, as you have the 999.local script in each of the daily, weekly, and monthly sub-directories of /etc/periodic to tell your scripts to run. Any future system updates could change the default files in those three directories, so if you modify those you may end up losing your scripts. Avoid that by setting up your own.
If you are running aTiger, the 999.local file may not exist, and you will have 500.daily, 500.weekly, and 500.monthly files inside their appropriate /etc/periodic directories. You should still create a daily.local, weekly.local, and monthly.local script file and place them in the /etc directory, and they will be called from the respective 500.* file.
Time Machine Not Backing Up Anymore? Try iBackup Instead.
Posted by technohermit in Apple, OS X, iBackup on 2009/11/08
[Check out iBackup here, if you hate to read.]
Well, what I thought was totally awesome the first time I ran it turned out to be not so good. OS X’s Time Machine let me down, and for the past three days I’ve been searching for a way to fix it. I managed to make a full backup to my FireWire drive the first time I ran it, and it seemed really cool. I am backing up to an external FireWire 400 drive, and trying to backup my MacBook Pro.
This is a notebook, and keeping Time Machine running didn’t seem like such a great thing for me. Keeping an external disk tethered to my MacBook Pro wouldn’t win any awards for mobility, for sure. I backed up, turned Time Machine off, and ejected my external drive. I was happy. A week later, I mounted the FireWire drive, and all seemed well. Turned on Time Machine, and it recognized the backup, I could flip through hourly backups, and it all looked great. I tried to run a new backup before going off to sleep, however, the next morning only 27KB had been transferred.
Obviously something went awry. No errors, no warnings, and the little backwards running icon in the menubar was still happily plugging along. What was apparent, though, is Time Machine had failed miserably. As I’ve looked deeper into this across many a forum, as well as various blogs, this is widespread and most users with difficulties such as this have moved to Snow Leopard 10.6.1. If you are running 10.6.0 and don’t have any issues with Time Machine, don’t update to 10.6.1. I did run across one cool widget that tells you Time Machines logs, called Time Machine Buddy.
I tried various things, from deleting the com.apple.timemachine.plist file in the Macintosh HD –> Library –> Preferences folder. This is a system-wide application and you won’t find a plist file in your home directory. I tried deleting the partial backup from my FireWire drive, and the alias file as well. I checked the .Trash folder on the FireWire drive to be sure there weren’t any remnants on the drive. Reboot after reboot, unmount and mount, nothing would fix it. So, as a last resort, I formatted the FireWire drive and started over. I made sure it was set up by the book. Nothing works to fix it, and the weird part is I never get an error. On my last attempt before looking into alternatives, I waited 6 hours to transfer 11KB. The furthest I ever had gotten was 5GB, which I thought would be it. Nope, stuck there for eternity. So, until Apple helps us out and gets it fixed, I’m moving on.
I found this sweet donationware application called iBackup. It doesn’t do nearly what Time Machine is supposed to, but for someone like me who just wants to backup my home folder, where my Sites, Downloads, Documents, etc. reside, it seems like it’s going to work out beautiful. 14GB of data transferred over to my FireWire drive in about 20 minutes, with no headaches. I like that. And it’s free for personal use, although I will probably throw the creator a donation because it’s what you should do when someone writes a handy application that you are going to keep using for eternity. I want them to keep publishing it, of course!
So here are some screenshots, you can read more about the Preferences and Plugins following the images (click to enlarge):
iBackup doesn’t support incremental backups, however, it does only copy items that have been modified. It uses straight up UNIX commands to copy your files, which you can see in the screenshot directly above, labeled Profile Preference 6. iBackup, on the initial backup uses the ditto command, and for subsequent backups (I’d rather they called them “synchronizations”), it uses rsync. As Apple has developers moving away from resource forks, rsync will be an easier tool to use for OS X consumers. If you hate the Terminal, this backup solution makes it quite easy to use a complicated command.
Other features I like to see, that Time Machine completely lacks, are the ability to backup to Windows hosted shares, via both AFP and SMB servers, ethernet connected drives, as well as encrypted sparse images. Quite nice. I must admit, I was going to try Time Machine down the road if I see Apple has fixed it’s problems, but something like iBackup for Mac is a product that will be tough to get me away from. Being able to use ethernet connected drives on my Gigabit network will certainly be a necessity; since I already own some LaCie drives, I never planned on buying a Time Capsule anyway.
Common Shortcuts for OS X And Their Windows Equivalents
Posted by technohermit in Apple, OS X, Uncategorized, Windows on 2009/11/01
If you are new to OS X, there are a bunch of shortcuts that you’ll immediately recognize from Windows. If you don’t use shortcuts at all, you really are missing out, as they are much faster than using the mouse in most situations. I tout programs like LaunchBar and Colibri because they make your computer usage faster. It is no different for shortcuts built-in to the operating system, so you should really take advantage of them!
Here is a short list of the most common on both OS X and Windows:
Since Vista was launched, you can create keyboard shortcuts to your programs through the Shortcut Icons that a program creates. You do this by:
- Right-Click the shortcut icon for the program
- Left-Click Properties
- In the “Shortcut Properties” box, find “Shortcut” tab and Left-Click on that.
- Left-Click the “Shortcut Key” box., and type in a letter you want to start the program. For example, type P for Photoshop.
- The box should update to show CTRL-ALT-P, as all shortcuts created in this manner automatically must begin with CTRL-ALT.
Resizing An Image Without An Image Editor — Using Automator
Posted by technohermit in Apple, Automator, OS X, Uncategorized on 2009/10/25
This is a fast and easy way to scale the size of an image (or a bunch of images) using OS X’s built in utility Automator. It is very simple (also crude), but it works and the results are pretty decent.
(You can scroll down to the end of the post if you just want the Automator applications and don’t care how I got there.)
First set up the job in Automator by opening the application in /Applications:
Next, choose workflow from the opening screen and select choose (or just hit enter if they’re already highlighted):
The next screen has built in functions to select by category. In the first column, select “Files & Folders“. Column 2’s selections are based upon what you select in column 1. Now the next additions to your workflow will depend upon your desired task. If you’d like to convert a single image, or if you plan on converting a bunch of images in a folder.
First we’ll cover how to make a simple workflow that you can use to select one image, start the workflow, and exit Automator.
With “Files & Folders“ selected in the first column, drag “Get Selected Finder Items“, followed by “Copy Finder Items” into the right hand area.
Next, in the first column, select Photos. Find “Scale Images” and drag that to the right hand actions area, so it is at the bottom. Your workflow should look like this:
Next, we want to adjust an options on ”Copy Finder Items” and “Scale Images” to force the workflow to ask for a values, rather than having to manually open Automator, change them, and click “Run”. That Would be tedious, and we are looking for simple. So, click the options button in the “Copy Finder Items” and ”Scale Images” portions of your workflow, and click the check box “Show This Action When Workflow Runs” in both of them:
With that done, just use the “Save As” in the file menu (⇧⌘S) and save the file as an application:
That’s it, really. You can now drag an image file onto the new application, it will ask you where to save the resized image, as well as ask you for the type of scale. You can set by percentage, or by pixels, and set the value based upon how you chose to scale it. Scaling by pixels appears to be based upon the width, and then uses the same scale factor to the height automatically.
Now, you can adjust this application to do a whole batch of files inside a folder, if you’d like. First, open Automator, click “Open Existing Workflow”, and choose your new application created above. Drag “Get Folder Contents” and place it under “Get Selected Finder Items” in the workflow. Your new workflow should look like this:
Again, click “Save As” in the file menu, and select a new name for this application. You can now drag a folder of images and drop it on the application to resize a batch of images.
There are other options in the Photos section of the Library of actions (the left hand column) such as changing the file type as well, for instance if you have a bunch of jpg’s and want to make them png’s for the web.
I hope this gets you interested in Automator–a totally useful and underrated tool–and happy image scaling!
Download the Single File Application or the Folder of Images Application here if you’d like. You can update and change them by opening them with Automator.
Simple Introduction To Apple’s Unix Using Terminal on OS X
Posted by technohermit in Apple, Entry Level Programming, OS X, OS X Shell, Uncategorized on 2009/10/24
This post is for someone interested in learning UNIX on Mac OS X Snow Leopard, but lacks experience using a command line, or has only C:\ prompt knowledge. I will show you, simply, how to map a DOS command to a UNIX command, and to save your profile so the alias name you create is persistent. If you are a shell scripting genius, this post is something you are encouraged to comment on and expand upon, as learning scripts and commands for OS X can be input many different ways. It never hurts to have different suggestions. I will try to make this at the minimum a weekly edition to my blog, and expand each article further than the next.
Let’s get started. First, open Terminal from your /username/Applications/Utilities folder. This is the command line utility for UNIX, by default it is Bash (Bourne Again Shell.)
You will see your entire present working directory prior to the $ prompt. The tilde (~) represents /Users/your home folder. The standard format is computer name: pwd. You can type the simple command pwd and the shell will respond with the folder you are currently accessing.
I like a cleaner shell screen, so I type bash, and hit enter. This opens a new bash shell, on top of the existing shell. Next, the command clear deletes the current Terminal text and starts with a fresh bash prompt. You end up with a Terminal screen that looks like this:
Here, we can start by showing the man (short for manual; built in UNIX help pages) page for the command ls (list), which is basically the dir command in DOS. Simply type man ls at the command line and hit enter. You can move down the pages line by line using the down arrow key on your keyboard. To exit the manual, simply type q.
The man page shows you the various options you can use along with the ls command, for example, ls -lia. This command is particularly useful when searching a directory for hidden files (they start with a period), as Finder refuses to display them by default:
Now, if you are used to DOS, here is a helpful way to stick with the commands you know, yet tell Terminal to run UNIX commands. You create an alias, basically a command name you make up mapped to a system command. If you want to use options such as -lia, you need to enclose the command in double quotes. The syntax of the alias command in bash is alias newCmdName=systemCmdName. The command in DOS for a directory listing like the one above is dir /a. So we can map dirA to ls -lia like so: alias dirA=”ls -lia”
Note that UNIX is also case-sensitive, for files as well as commands:
You can simplify entering commands by using the up arrow to cycle through previously typed in commands. The history command, saves the commands you enter by line number, which you can view by typing history. To execute the line number, type an exclamation point followed by the line number:
Now, to save this new alias dirA you created into your bash profile. This way it doesn’t get erased when we kill the shell and quit Terminal. You may not have a profile set up for bash in your home directory, so what you need to do is create one. Bash will look for .bash_profile first, so it is best to name any profile you want to use on a regular basis with this name. It is a hidden file, so you need to have the period in the file name. For simplicity, you can create a simple text file in your favorite text editor, name it bash_profile (without an extension)and save it in your home directory. Write the exact command on one line like so: alias dirA=”ls-lia”
Save the file, and then change the name in Terminal. Use the command mv to change the name so it begins with a period. Simply type mv bash_profile .bash_profile and press enter:
That did two things: one, you moved the file; two, you learned that mv is the same command as the DOS command move. You can follow the procedure above to make an alias for the mv command, and place it on the next line in your .bash_profile, so it remains permanent for your login shell. If you like running an “non-login” shell as I do above, you can use the command cp to copy your .bash_profile to .bashrc like so: cp .bash_profile .bashrc
Here is a short list of a few DOS commands, along with their respective UNIX bash counterparts (pdf of list here):
|
DOS COMMAND |
UNIX COMMAND |
|
DIR |
LS |
|
MOVE |
MV |
|
COPY |
CP |
|
FIND |
GREP, FGREP, EGREP |
|
MEM |
TOP (virtual memory use VM_STAT) *use ctrl-c to end TOP command* |
|
CD |
CD (PWD to display current directory) |
|
DEL |
RM |
That’s all for this quick lesson. Stop by next week for more DOS examples in UNIX, and (hopefully) working with vi, UNIX’s text editor.
Typing Special (Unicode) Characters in Snow Leopard
Posted by technohermit in Apple, OS X, System Preferences, Uncategorized on 2009/10/22
[You can find the hex code for common symbols here if you already set up your Unicode Keyboard layout. ]
Wondering how to make special characters, such as the Command (⌘) Symbol in OS X Snow Leopard? Maybe you want to add the Euro (€) symbol? It’s not as hard as you may think. They are Unicode characters, and there are a few simple steps to make them easy to type on screen.
First, open System Preferences. I like to use LaunchBar, so I type ^Tab, press”sy”, and hit enter. For those of you who like the mouse (gasp!): System Preferences is in your dock by default, or it’s found in your Applications folder.
Once there, click the flag icon “Language & Text”. Next, click “Input Sources”:
Scroll down until you find Unicode Hex Input, and check the box. I also like to have the option shown in my menu bar by the clock, so I leave the “Show Input menu in menu bar” box ticked:
In the same window, click the “Keyboard Shortcuts” button. In the next window, click “Keyboard & Text Input”:
Here is where you decide how to switch between your normal keyboard and the Unicode Hex keyboard layout. The options are called “Select the previous input source” and “Select next source in Input menu”. To change the option, click where the keys are to the right of the name of the shortcut, select all of the keys in the box, and then input your new keystrokes. I chose to hold down Control, Option, Command, and Space Bar (daunting I know.)
Holding down your shortcut gives you this window where you can arrow key through your options:
The key difference between Unicode and US is the function of the option key. In Unicode layout, you hold down the option key and enter the Hex code for the symbol you’d like to type on screen. For example, holding down option and pressing 2 in a US keyboard layout gives you the trademark symbol, ™. Whereas in the Unicode Hex layout, you need to hold down option and type four keystokes to make a symbol. ⌘ is Option and then 2318.
To find the Unicode “code” for your symbol, open the Character Viewer by pressing option-command-T (⌥⌘T) or by clicking the flag near your clock in the menu bar, and then clicking on Show Character Viewer:
Looking at the Character Viewer (⌥⌘T), you can attempt to find your symbol with the search field at the bottom. Clicking on a symbol will tell you which four keys to type while holding down option (and being in the U+ keyboard layout):
I chose the Euro as an example, and you can see in order to type the symbol, I hold down option and press 20ac (caps not necessary, although it is shown that way): €.
The keyboard viewer also helps identify the keymap of a new language layout. Although there isn’t a noticeable change between US and Unicode, you may see quite a change picking something like Canadian French or Dvorak.
Good luck and happy character typing!
PS– To type the apple () symbol, in a US keyboard layout, hold down Option+Shift, and press k. No special keyboard required!
Safari Webpage Preview
Check out my update on this article here.
I was just going through the idea of a simple script to clear Safari’s cache. Being a new Snow Leopard recruit, I didn’t know where the cache is located, so I started looking in the usual suspect places. Before I got far, I landed in the ~/Library/Caches/com.apple.Safari/Webpage Previews folder. For those of you who don’t realize the significance of that folder, I was with you up until about 5 minutes ago.
This folder contained about 500MB of webpage snapshots of various places I’d visited over the past, oh, 4 days. The reason behind all the images? Cover Flow. When you browse your bookmarks bar in Cover Flow, Safari can show you all of the sites in your history with full page images. This is cool, but seriously….does it need to keep them all? If you hit something cool like my site here (*cough*) more than once a day, it will take more than one image. 500MB?!? I never knew that just Safari’s iteration of Cover Flow was taking up that much disk space on my system. That’s a lot of space! Fortunately there is a really simple solution to getting rid of the images.
First, go to your Safari menu and click “Reset Safari”(current as of 4.0.3 on Snow Leopard):


There are many options, and I do recommend once in a while resetting all of them (check all the boxes) to keep your web browsing going smooth. This particular option, if you have a small amount of free hard disk space, could make a lot of difference on system performance. Depending on your browsing habits, this could seriously chew up a lot of disk. Clear it out, and then use the web as you normally would. Before you go to bed, to work, or whatever, check this folder for size again:
~/Library/Caches/com.apple.Safari/Webpage Previews, this way you have a good idea of how much space this takes up in one of your normal web sessions.





























