Skip to content

Instantly share code, notes, and snippets.

@jacobsalmela
Created August 12, 2014 12:27
Show Gist options
  • Save jacobsalmela/db93598c827fdc721acb to your computer and use it in GitHub Desktop.
Save jacobsalmela/db93598c827fdc721acb to your computer and use it in GitHub Desktop.
(OS X) Speak and copy the serial number
#!/bin/bash
#----------AUTHOR------------
# Jacob Salmela
# 3 December 2013
#----------RESOURCES---------
# http://stackoverflow.com/questions/12230762/insert-characters-into-a-string-in-bash
#---------DESCRIPTION--------
# Copies the computers serial number into the clipboard and then speaks it aloud so you can write it down
# It currently is setup for serial numbers that are 12 digits long
#-----------USAGE------------
# To run:
#
# 0. Move this script to /usr/bin or /usr/sbin depending on your preference
# 1. Rename it to something like "snum" so it is easier to call
# 2. Exit out of your shell session and log back in for it to trigger
# 3. Run the program by typing snum or /usr/bin/snum
#
#----------VARIABLES---------
# Change this to the voice of your preference
# I have it default to Samantha, because it is the voice commonly associated with Apple products
voiceChoice="Samantha"
# This variable parses the system profiler command via awk and prints only the serial number
serialNum=$(system_profiler SPHardwareDataType | awk '/Serial Number \(system\)/ {print $4}')
# This variable echos back each character in the serial number, but appends two commas and two elipsises
# When the computer speaks the serial number, it interprets the commas and elipsises as an indicator to speak more slowly
# This makes it easier to hear the number when the Mac speaks it
serialForSpeech=$(echo ${serialNum:0:1}...,...,\
${serialNum:1:1}...,...,\
${serialNum:2:1}...,...,\
${serialNum:3:1}...,...,\
${serialNum:4:1}...,...,\
${serialNum:5:1}...,...,\
${serialNum:6:1}...,...,\
${serialNum:7:1}...,...,\
${serialNum:8:1}...,...,\
${serialNum:9:1}...,...,\
${serialNum:10:1}...,...,\
${serialNum:11:1}...,...,\
${serialNum:12:1}...,...,)
#----------FUNCTIONS---------
#################
function copySN()
{
# This echos the serial number and than saves it to the clipboard for easy pasting
echo $serialNum | pbcopy
}
##################
function speakSN()
{
# Say command using the $voiceChoice variable from above
# Output of this command is sent into the Sarlaac Pit so it doesn't clutter up the screen with unnecessary information
say -v $voiceChoice "Get ready, I am about to tell you the serial number. It is $serialForSpeech" &> /dev/null
}
#--------------------------------
#---------BEGIN SCRIPT-----------
#--------------------------------
copySN
speakSN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment