Adrian Nier Code

Back to overview

Open fonts folders

Last modification: Sunday, February 28, 2010 03:27 pm

Creates a new folder in the current user's Library named Fonts (Deactivated) and opens it together with the regular user Fonts folder. This is for users who want to manage their fonts by simply dragging them in and out from their Fonts folder.

Implementation

on run
   
   -- Set position and size information for Finder windows
   set _x to 32
   set _y to 64
   set _windowWidth to 456
   set _windowHeight to 512
   set _horizontalSpace to 32
   
   -- Generate bounds for both Finder windows
   set _bounds1 to {_x, _y, _x + _windowWidth, _y + _windowHeight}
   set _bounds2 to {_x + _windowWidth + _horizontalSpace, _y, _x + (_windowWidth * 2) + _horizontalSpace, _y + _windowHeight}
   
   -- Set the background color for both Finder windows
   set _backgroundColor1 to {59110, 59110, 65535}
   set _backgroundColor2 to {65535, 52428, 52428}
   
   -- Check wether the Fonts and Fonts (Deactivated) folders exist
   copy checkFontsFolders() to {_folderPath1, _folderPath2}
   
   -- Open the Finder windows
   newFinderWindowWithPath_andBounds(_folderPath1, _bounds1, _backgroundColor1)
   newFinderWindowWithPath_andBounds(_folderPath2, _bounds2, _backgroundColor2)
   
end run

on newFinderWindowWithPath_andBounds(_path, _bounds, _color)
   
   tell application "Finder"
      set _window to make new Finder window at the end of Finder windows with properties {bounds:_bounds, target:folder _path}
      
      tell _window
         set target to folder _path
         set bounds to _bounds
         set current view to icon view
         
      end tell
      
      tell icon view options of _window
         
         
         set background color to _color
         set text size to 10
         set arrangement to arranged by name
         set icon size to 16
         set shows item info to false
         set shows icon preview to false
         set label position to right
         
      end tell
      
   end tell
   
end newFinderWindowWithPath_andBounds

on checkFontsFolders()
   
   -- Get the path to the user's fonts folder as suggested by the system
   set _fontsFolderPath to (path to fonts folder from user domain) as string
   
   -- Check wether the fonts folder exists, create it if not
   checkFolder(_fontsFolderPath)
   
   -- Get the name of the fonts folder and its parent
   tell application "System Events"
      set _fontsFolderName to name of folder _fontsFolderPath
      set _parentPath to path of container of folder _fontsFolderPath
   end tell
   
   -- Generate name and path of the folder for deactivated fonts
   set _deactivatedFontsFolderName to _fontsFolderName & " (Deactivated)"
   set _deactivatedFontsFolderPath to _parentPath & _deactivatedFontsFolderName & ":"
   
   -- Check wether the folder for deactivated fonts exists, create it if not
   checkFolder(_deactivatedFontsFolderPath)
   
   -- Set the color label for both folders
   tell application "Finder"
      set the label index of folder _fontsFolderPath to 4 -- Blue
      set the label index of folder _deactivatedFontsFolderPath to 2 -- Red
   end tell
   
   return {_fontsFolderPath, _deactivatedFontsFolderPath}
   
end checkFontsFolders

on checkFolder(_path)
   tell application "System Events" to set _folderExists to exists folder _path
   if _folderExists is false then
      do shell script "mkdir -p " & quoted form of (POSIX path of _path)
   end if
end checkFolder