This is a follow up on Random Terminal Colors

If You like randoms images on the Mac Terminal, here a way to achive it for iTerm2.

I have placed my script in ~/Dropbox/Scripts/osx/RandomImagesiTerm2.scpt - look at Random Terminal Colors for ways to run it automatically.

 

The folder where images are stored are in osx "/Users/npn/Dropbox/Wallpapers" - which in AppleScript becomes "Macintosh HD:Users:npn:Dropbox:Wallpapers" and this is more or less hardcoded in the script; only the username of the logged in user is dynamic.

iTerm2.app

The script itself for "iTerm2":

on replace_chars(this_text, search_string, replacement_string)
 set AppleScript's text item delimiters to the search_string
 set the item_list to every text item of this_text
 set AppleScript's text item delimiters to the replacement_string
 set this_text to the item_list as string
 set AppleScript's text item delimiters to ""
 return this_text
end replace_chars

set userName to short user name of (system info) as text

set wallPaperPath to "Macintosh HD:Users:" & userName & ":Dropbox:Wallpapers" as text

tell application "Finder"
  set randomImage to some file of folder wallPaperPath
end tell

set thePath to replace_chars(randomImage as string, ":", "/")
set thePath to replace_chars(thePath,"Macintosh HD","")

tell application "iTerm2"
  tell current session of current window
    set background image to thePath
  end tell
end tell

  • No labels