#!/usr/bin/perl ############################################################################### # # itunes_font_size.pl # # This script will edit the list and source font size in iTunes # # written by: Robert Jacobson (http://www.pobox.com/~teridon/itunesscripts) # Last Updated: 2011-Aug-21 # Version 2.0 # # This script is GPL v2. see http://www.gnu.org/copyleft/gpl.html # # Change record # 1.0 creation # 1.1 update for iTunes 9.0.3 (no change to font address) # 2.0 update for iTunes 10.4 (use 'defaults' command on TextStyles.plist; resource file no longer exists) # ############################################################################### use strict; use File::Basename; my $PROGNAME = basename($0); my $VERSION = "2.0"; my $AUTHOR = "Robert Jacobson"; my $HOMEPAGE = "http://www.pobox.com/~teridon/"; my $YEAR = 2011; my $GNU_URL = "http://www.gnu.org/copyleft/gpl.html"; { print "**************************************************************\n" . "$PROGNAME version $VERSION, Copyright (C) $YEAR $AUTHOR\n" . "Visit $HOMEPAGE for updates\n" . "$PROGNAME comes with ABSOLUTELY NO WARRANTY;\n". "This is free software, and you are welcome\n" . "to redistribute it under certain conditions\n" . "for details see $GNU_URL.\n" . "**************************************************************\n" . "\n" ; } # Check if iTunes is running my $ps = `ps aux | grep -v grep | grep iTunes.app/Contents/MacOS/iT | grep -v iTunesHelper`; if ( $ps =~ m/iTunes/ ) { print "\niTunes is running\! please exit it and try again\n"; exit; } my $default_small_size = 11; my $default_large_size = 13; my $dir = '/Applications/iTunes.app/Contents/Resources/English.lproj'; #$dir = "."; my $file = 'TextStyles'; my $small_id = 9002; my $large_id = 9003; #$file = 'test'; my $rsrc_file = "$dir/$file" . ".plist"; #Get iTunes version print "Getting iTunes Version...\n"; chomp (my $itunes_version = `system_profiler SPApplicationsDataType | grep -A 4 iTunes: | grep Version`); $itunes_version =~ s/.* (\d.*)/$1/; print "iTunes version: \'$itunes_version\'\n"; # Make sure user is root chomp (my $user = `whoami`); if ($user ne "root") { print "\nNOTE: You must be root to edit the font size\n"; print "Run this script using 'sudo', e.g.:\n"; print " sudo perl $0\n"; exit; } print "Getting font sizes...\n"; my $curr_size_small = `defaults read /Applications/iTunes.app/Contents/Resources/English.lproj/TextStyles $small_id | grep size | awk '{print \$3}'`; print "foo $curr_size_small\n"; my $curr_size_large = `defaults read /Applications/iTunes.app/Contents/Resources/English.lproj/$file $large_id | grep size | awk '{print \$3}'`; $curr_size_small =~ s/;//; $curr_size_large =~ s/;//; printf("current small font size: %d\n", $curr_size_small ); printf("current large font size: %d\n", $curr_size_large ); my $new_small_size = $curr_size_small; my $new_large_size = $curr_size_large; print "\nEnter new small font size\n(or just hit enter to use $curr_size_small ): \n"; chomp(my $small_input = ); if ($small_input =~ m/^\d+$/) { $new_small_size = $small_input; } elsif ( $small_input =~ m/^$/ ) { # keep current } else { print "Error: invalid input $small_input\n"; exit; } print "using $new_small_size for small font\n"; print "\nEnter new large font size\n(or just hit enter to use $curr_size_large ): \n"; chomp(my $large_input = ); if ($large_input =~ m/^\d+$/) { $new_large_size = $large_input; } elsif ( $large_input =~ m/^$/ ) { # keep current } else { print "Error: invalid input $large_input\n"; exit; } print "using $new_large_size for large font\n"; my $time = time(); print "Backing up current iTunes resource file to\n"; print "${rsrc_file}.${time}\n"; system("cp -p $rsrc_file ${rsrc_file}.${time}" ) == 0 or die "failed to make backup, aborting: $!"; print "Changing $file...\n"; system("defaults write /Applications/iTunes.app/Contents/Resources/English.lproj/TextStyles $small_id -dict-add size $new_small_size"); system("defaults write /Applications/iTunes.app/Contents/Resources/English.lproj/TextStyles $large_id -dict-add size $new_large_size"); system("chmod a+r $rsrc_file"); print "NOTE: to restore from the backup, do:\n"; print "sudo cp -p ${rsrc_file}.${time} ${rsrc_file}\n"; print "\nDone!\n\n";