Installer ce thème
Generate and Set a Random Valid MAC Address from the Command Line in OS X

Using the command line, you can combine the two events into a single action to generate a valid MAC and then set it immediately.

Launch the Terminal and paste the following onto a single line:

openssl rand -hex 1 | tr '[:lower:]' '[:upper:]' | xargs echo "obase=2;ibase=16;" | bc | cut -c1-6 | sed 's/$/00/' | xargs echo "obase=16;ibase=2;" | bc | sed "s/$/:$(openssl rand -hex 5 | sed 's/\(..\)/\1:/g; s/.$//' | tr '[:lower:]' '[:upper:]')/" | xargs sudo ifconfig en0 ether

There is no confirmation or output, the MAC address is set immediately which you can verify with the following command:

ifconfig en0 |grep ether

You will probably need to reconnect to the wireless router after issuing the command, and in some cases turn wi-fi on and off again.

If you intend on using this often, setting up an alias in .bash_profile would be a good idea to avoid having to cut and paste the massive block of text.

Long list of defaults commands

# Disable menu bar transparency
defaults write NSGlobalDomain AppleEnableMenuBarTransparency -bool false
# Show remaining battery time; hide percentage
defaults write com.apple.menuextra.battery ShowPercent -string “NO”
defaults write com.apple.menuextra.battery ShowTime -string “YES”

Afficher davantage

Disable the File Extension Change Warning in Mac OS X

Assuming you have file extensions shown in the OS X Finder, attempting to change a file extension causes a warning dialog with a confirmation box to appear. This is annoying if you know what you’re doing and you have a compelling reason to change extensions, so let’s turn it off using the command line and defaults write.

First, open the Terminal, located within the /Applications/Utilities/ directory, then copy and paste in the following command:

defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false

Follow that up by relaunching the Finder with killall:

killall Finder

To reverse the change and get the warning back when you attempt to change file extensions, use the following defaults write command:

defaults write com.apple.finder FXEnableExtensionChangeWarning -bool true

Kill the Finder again for changes to take effect.

Change Terminal Apps Default Shell in OS X
  • Open Preferences from the Terminal menu, click the “Startup” tab
  • Under “Shells open with” choose “Command (complete path)” and set the new shell

Change Shell in Terminal

Change a User Default Login Shell in Mac OS X

You can also change the default shell through the command line itself using the chsh command, this will be necessary if you want the default shell to be different when logging in with SSH or telnet. You’ll need to authenticate each change:

ksh:
chsh -s /bin/ksh

tcsh:
chsh -s /bin/tcsh

bash (default):
chsh -s /bin/bash

sh:
chsh -s /bin/sh

How to Remotely Sleep a Mac from Anywhere with SSH or an iPhone

Ever been away from your Mac and wished you could put it to sleep remotely? Maybe you accidentally left a Mac on at home or at work, or maybe you just left a Mac running so a download could complete. You don’t have to leave it running while you’re gone though, here are two different ways you can remotely sleep a Mac. The first method uses SSH and thus requires Terminal access, and the other uses just email which allows you to sleep a Mac with an iPhone or iPad just by sending a message from a verified email address.

Remotely Sleep a Mac with SSH

The first method assumes knowledge of SSH and the Terminal and is more advanced than the email method mentioned below. You will need to enable SSH server on the target Mac beforehand for this to work, this can be done quickly through System Preferences > Network > Enable Remote Login. Make note of the Macs IP address too, that is what you’ll connect to it with.

    • Use Terminal and SSH to the target Mac, be sure to specify the appropriate user name and IP address:

ssh username@127.0.0.1

    • Once logged in, type the following command:

osascript -e 'tell application "System Events" to sleep'

There is no warning or hesitation, the target Mac immediately goes to sleep and the SSH connection will die as a result. The main downside to this method is you’ll need access to an SSH client to activate the sleep method, these are widely available for Mac OS X (Terminal), Windows (PuTTY), and iOS (Prompt or MobileTerminal). If you don’t want to have to use SSH to sleep the Mac, you can also use put Macs to sleep remotely by sending an email, it takes a little bit more to set up though.

Remotely Sleep a Mac with an iPhone via eMail

This may be the best method because you can put the Mac to sleep anytime by shooting off an email from an iPhone (or iPad 3G/4G). You will need to always have Mail.app running on the target Mac for this to work:

    • Open AppleScript Editor (/Applications/Utilities/)
    • Create a new AppleScript containing the following exactly:

tell application "System Events" to sleep
Remote Sleep a Mac

    • Save the AppleScript as “sleepmac.scpt” and put it in your Documents folder
    • Open Mail app, pull down Mail menu, and select “Preferences”
    • Click on “Rules” and choose “Add Rule”
    • Name the description something like “Sleep Mac” and create new conditions with the following options:
      • if: ALL
      • From – Contains – (specify verified email address here)
      • Subject – Is equal to – “Sleep now”
      • Perform following actions: Run AppleScript – ~/Documents/sleepmac.scpt

Remote Sleep a Mac via Email

  • Click “OK” to add the new rule set and click “Apply” to apply the sleep ruleset to all inboxes

Verify everything is working by sending an email from the address you specified with the subject “Sleep now”, the Mac should sleep immediately. If it doesn’t work, verify the AppleScript was set up properly, and that the Rule set is configured properly and for the recipient inbox that Mail.app is configured for. With the ruleset shown in the screenshot above, any email sent from mac@osxdaily.com with the subject “Sleep now” will sleep the target Mac immediately.

Both SSH and sleep through Mail have been tested to work on Macs running OS X 10.7 Lion and OS X 10.8 Mountain Lion, though there is no technical limitation and they should function identically in earlier versions of Mac OS X as well.

Create ISO Images from the Command Line

You can create ISO images from any source disk or data by using the command line in Mac OS X. This isn’t too different than burning them through Terminal, and you can use either the hdiutil tool or dd command.

While the command line is generally reserved for advanced users, using it to create ISO’s isn’t too complicated and will save you the hassle of having to download any third party apps. If you’re new to the Terminal, remember that dragging & dropping files into the Terminal window will print their full path, making it easy to point to source files and preventing any navigation through the command line.

Creating an ISO with hdiutil

The most reliable method is uses hdiutil, here is the syntax:

hdiutil makehybrid -iso -joliet -o image.iso /path/to/source

Here’s an example, creating an iso from a Windows 7 installer disc, with the end result showing up on the desktop:

hdiutil makehybrid -iso -joliet -o ~/Desktop/Windows7.iso /Volumes/Windows\ 7\ Install

The -joliet flag is necessary to make the iso fully compatible with Windows and other OS’s, though if your only requirement is to use the iso on a Mac you can leave it off.

Making an ISO with dd

Another approach is by switching around a previously discussed dd command, which makes it go from burning an image to creating an image. This may not be as reliable and it requires additional steps, so use dd only if you have a good reason not to use the primary hdiutil method.

Use the ‘diskutil list’ command to discover the disks identifier that you will need to make an ISO with dd from.

dd if=/dev/dvd of=/destination/path/dvd.iso

dd is often faster than hdiutil, but it’s definitely for more advanced users.

How to Resolve a “Partition Failed” Error in Mac OS X

Partition Failed error

If you have attempted to partition a drive from Mac OS X and received a “Partition failed” message with the error “Couldn’t modify partition map because file system verification failed.” you can fix the problem with the file system check command line utility. To do this properly, you’ll need to boot into Single User Mode as well:

    1. Reboot the Mac into Single User Mode by holding Command+S during boot
    2. At the command prompt, type:

/sbin/fsck -fy

  1. When fsck is complete, type “exit” or “reboot” to reboot
  2. Boot the Mac as usual, verify the disk again in Disk Utility, and partition as usual

Boot the Mac as usual and relaunch Disk Utility to verify the disk. Go ahead and partition the drive as usual, this time without any such error message.

I have encountered this error a few times when partitioning the boot drive from OS X Lion, most recently after a clean installation when setting up dual boot for OS X Lion and Mountain Lion. The cause of this remains to be seen, and repairing the disk from Disk Utility itself doesn’t work, even when in Single User Mode or when booting from another drive.

Keep your files in sync using a simple command line utility

Macs have long been equipped with a file syncing utility unknown by most users. Remote sync, or rsync, is a way to synchronize files and directories through the command line interface on Unix-based machines. This easy-to-use utility is commonly used for backing up your data, but can synchronize files for any other purpose you choose to use it for. Remote sync can be better than other backup methods because of its speed, and because it doesn’t require any special permissions to execute an rsync command. With just a small knowledge of the command line, you can be backing up in no time with rsync.

Afficher davantage

Change (Spoof) a MAC Address in OS X Lion & OS X Mountain Lion

Change a MAC Address in Mac OS X

A MAC address is a unique identification number assigned to network interfaces, these can be attached to physical hardware like NIC and Wi-Fi cards or assigned to virtual machines. On some occasions, you’ll need to change a MAC address to another ID.

We’ve received a few questions about this recently because the process of changing (sometimes called spoofing) these addresses has changed slightly from version to version in Mac OS X. With that in mind, we will show you how to change a MAC address in the latest versions of OS X 10.7 and 10.8. Launch the Terminal found within /Applications/Utilities/ to get started.

Get a New MAC Address
The first thing you’ll want to do is retrieve the intended MAC address. If you have one in mind then use that, but if you aren’t trying to spoof a specific address and just need a random one, use the following command to generate one with openssl:

openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'

MAC addresses are always in the format of xx:xx:xx:xx:xx:xx, yours must conform to this format in order to work. For the purpose of this walkthrough the randomly generated address of “d4:33:a3:ed:f2:12 ” will be used.

Changing the MAC Address

If you aren’t in the Terminal yet, open it now. We’ll use the interface en0 for this, but yours could be en1 (read notes at bottom). The command for changing the MAC address is as follows:

sudo ifconfig en0 ether xx:xx:xx:xx:xx:xx

Replace “xx:xx:xx:xx:xx:xx” with the desired MAC address, in the example case this will look like:

sudo ifconfig en0 ether d4:33:a3:ed:f2:12

Hit return and enter the administrators password to set the new address. To confirm it has been changed, type the following:

ifconfig en0 |grep ether

You can also find itin Network preferences, though the GUI doesn’t always report the MAC change immediately, instead waiting until the network connection has been cycled.

Notes & Troubleshooting

  • If you aren’t sure which interface to use (en0, en1, etc), type “ifconfig” and find it that way. For MacBook Air without an ethernet port the en0 is usually the Wi-Fi interface, whereas a MacBook, iMac, Mac Mini, MacBook Pro, or any Mac that has an ethernet port will probably use en1 for Wi-Fi instead
  • You may want to note the default hardware MAC address before beginning
  • Some Macs will use the following command instead:

    sudo ifconfig en1 Wi-Fi xx:xx:xx:xx:xx:xx

    OS X Lion and later renamed ‘airport’ to Wi-Fi and thus the naming change

How to Tell If Someone Was Using Your Mac

Find Out If Someone Was Using Your Mac with Console

This works best if you put a Mac to sleep while away, since what we’re looking for are system wake events. If you aren’t sleeping a Mac while gone from the computer, start doing so now to track this wake data.

  • Use Spotlight (Command+Spacebar) to search for and open “Console”
  • Click the search bar in the upper right corner of Console and type “Wake” to sort the system logs for wake events
  • Scroll to the bottom of the list to find the most recent events, search around in the listed data for a wake entry that corresponds to the time you suspect someone used the computer

First you’ll want to make note of the time since that alone can give you the information you’re looking for. Furthermore, by reading the wake reasons you’ll be able to see how the Mac was woken up and by what method. For example, Mac laptops will show “EC.LidOpen (User)” or “LID0″ to indicate the Mac was woken by opening the screens lid. All Macs will show EHC or EHC2 to demonstrate that the Mac was woken by touching the keyboard or trackpad. OHC or USB generally indicates an external USB device or mouse was used to wake the Mac, and so forth. Some of the exact syntax for wake reasons will vary per version of OS X, but most of the codes are similar enough to draw shared conclusions.

Here are some example entries of what you may see in Console:
2/24/12 3:22:26.000 PM kernel: Wake reason: EC.SleepTimer (SleepTimer)
2/24/12 3:40:31.000 PM kernel: Wake reason: EC.LidOpen (User)
2/24/12 5:23:40.000 PM kernel: Wake reason: EC.SleepTimer (SleepTimer)
2/24/12 8:11:03.000 PM kernel: Wake reason: EC.LidOpen (User)
2/24/12 9:05:09.000 PM kernel: Wake reason: EC.LidOpen (User)
2/24/12 9:32:06.000 PM kernel: Wake reason: EC.LidOpen (User)
2/25/12 00:51:44.000 AM kernel: Wake reason: EHC2

What you are ultimately looking for is a date, time, or a wake event that doesn’t correspond to your own regular Mac use. Perhaps waking by trackpad (EHC2) at midnight is suspicious, or maybe it was unusual to have someone open the lid of the laptop at 3:40 in the afternoon yesterday. Ultimately it is up to you to determine what is suspicious or out of place, but by looking at system logs you can get data that is practically guaranteed to be accurate because most users wouldn’t think to interfere with these logs.

Finding Wake Information from the Command Line
If you’re more inclined to use the command line, or if you want to check wake events on a remote Mac via SSH, try using grep with the syslog command to look for “Wake” or “Wake reason”:

syslog |grep -i "Wake reason"

Using syslog with grep displays the exact same wake information as Console would, but because it’s accessible from the command line it can be more powerful for advanced users.