Posted by dmccoy | Posted in Applescript, Code, OS X | Posted on 10-11-2009
tell application "iChat"
tell application "iChat" to set messagelist to get status message of every buddy
where status is not offline
set msglistcount to count messagelist
set theMessageList to {}
repeat with x from 1 to msglistcount
if item x of messagelist is not "" then
copy item x of messagelist to end of theMessageList
end if
msglistcount = msglistcount - 1
end repeat
set newStatus to some item of theMessageList
set status message to "i'm in your internets stealing your status messages : " & newStatus
end tell
Posted by dmccoy | Posted in Command-Line, Linux, OS X, Ubuntu | Posted on 21-07-2009
For most server administrators doing system updates or installing patches via a command shell is normal, but for the average user trying to patch his new system, this task might be a little difficult. Opening a terminal and downloading a file, just by typing in a few words, is not as simple as clicking a download icon on a website, tho, once you learn how to use Wget or cURL, it will be.
From my understanding, Wget is a stand-alone application, that is command-line only. And, cURL is a cross-platfrom API library called libcurl. Personally, I like Wget better then cURL, but that’s just because I am bias.
If you want to know all the nitty-gritty differences, check out curl vs Wget.
Wget – The non-interactive network downloader. (I refer to it as, WWW Get or Web Get).
wget [option]… [URL]…
curl – transfer a URL
curl [options] [URL...]
How to download a file with wget:
wget http://domain.com/path/to/file.zip
How to download a file with cURL:
curl -O http://domain.com/path/to/file.zip
or
curl http://domain.com/path/to/file.zip > file.zip
After I’ve determine which interfaces are active on my computer(s), I can use this script to report back the IP address of said interface.
# input String ("en0")
# output String IP
function get_network_interface_ip($interface) {
@exec('/usr/sbin/ipconfig getifaddr '. $interface, $retval);
return $retval[0];
}// end get_network_iterface_ip
echo get_network_interface_ip($interface);
I use this script, after I determine what available interfaces the computer has, to report which interfaces are active.
# input String ("en0")
# output "NULL or "Active"
function check_interface_activity($interface){
@exec('ifconfig| awk \'/flags=|media|inet / {if (substr($2, 1, 6) == "flags=") printf("\n%s ", $1);
else if ($1 == "inet") printf("%s ", $2);
else if ($1 == "media:") printf(substr($0, 9))}\' | awk \'$1 ~ /^'.$interface.'/\' | awk \'{print $7}\'',$retval);
return $retval[0];
} // end check_interface
echo check_interface($interface);
I use this script to gather all Ethernet based network activity to determine which network port is active and then determine what the hardware address and IP address are.
# input NONE
# output String ("en0, en1")
function get_all_active_network_interfaces() {
$inclusion = array(en0,en1);
@exec('/sbin/ifconfig -lu', $retval);
$interfaces = explode(" ",$retval[0]);
$ret=NULL;
foreach($interfaces as $interface){
if (in_array($interface,$inclusion)){
$ret.=$interface ." \n \r";
} // end if
}// end foreach
return $ret;
} // end get_all_active_network_interfaces
echo get_all_active_network_interfaces();
This script is similar to the above script, but doesn’t include the constraints of the inclusion list.
# input NONE
# output String ("en0, en1, etc")
function get_all_active_network_interfaces() {
@exec('/sbin/ifconfig -lu', $retval);
$interfaces = explode(" ",$retval[0]);
$ret=NULL;
foreach($interfaces as $interface){
$ret .= $interface ." \n \r";
}// end foreach
return $ret;
} // end get_all_active_network_interfaces
echo get_all_active_network_interfaces();
Posted by dmccoy | Posted in Bash, Code, Command-Line, OS X | Posted on 17-07-2009
scutil is OS X’s way of managing system configuration parameters. These parameters not only include HostName, ComputerName, LocalHostName, but basically anything that the configd daemon uses.
Most of those files are located in
/System/Library/SystemConfiguration/
/Library/Preferences/SystemConfiguration/
.../preferences/
.../NetworkInterfaces/
.../VirturalNetworkInterfaces/
To enter the scutil prompt, type
To view all the scutil commands, type
To get a list of all the scutil keys, type “list” or “list + [Pattern]”
To view the contents of a key, type “show + [Pattern”
> show Setup:/Network/Global/IPv4
This will result in a pattern like this.
< dictionary > {
ServiceOrder : {
0 : 59267386-49A6-401F-A23E-BE372AD748EB
1 : 68719F97-53F0-479E-A497-8A3B809728D1
2 : E936454A-40CA-4867-A759-61D6C38F5972
}
}
To get your computer name, local host name or host name type,
/usr/sbin/scutil --get ComputerName
/usr/sbin/scutil --get LocalHostName
/usr/sbin/scutil --get HostName
And setting those names are just as easy.
/usr/sbin/scutil --set ComputerName NEWNAME
/usr/sbin/scutil --set LocalHostName NEWNAME
/usr/sbin/scutil --set HostName NEWNAME
On a side note. ComputerName HostName can be set to blank, but LocalHostName needs at least 1 character.
To quit scutil type,
Family Commands of scutil are
/usr/sbin/scutil -- Manage system configuration parameters
/usr/sbin/scselect -- Select system configuration "location"
/usr/sbin/configd -- -- System Configuration Daemon