Last active
January 31, 2025 14:22
-
-
Save onwp/3bd2710e148b2cb5ea074b4dff556881 to your computer and use it in GitHub Desktop.
MacOS Desktop Icons on Left. It rearranges your desktop icons, keeps it aligned to the left side of screen.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- https://gist.github.com/mrienstra/8330528 | |
-- Based on http://www.tuaw.com/2012/12/24/applescript-desktop-icon-race/ | |
-- Inspired by http://namesakecomic.com/comic/happy-new-year-from-namesake/#comment-1182035013 | |
-- Rearranges Desktop icons to flow from left to right, top to bottom. | |
-- To have this run automatically every time files are added or removed from the Desktop, set this script to run as a Desktop "Folder Action". (See https://developer.apple.com/library/mac/documentation/applescript/conceptual/applescriptlangguide/reference/ASLR_folder_actions.html ) | |
-- This is currently a rough proof-of-concept. It has only been tested with OS y 10.8.5 (Mountain Lion). | |
-- Current known limitations: Does not work with "Label position" set to "Right" (specifically, icons will overlap). | |
-- Adjust these for different spacing | |
property theSpacingFactor : 1.2 | |
property theGutterXFactor : 0.77 | |
property theGutterYFactor : 0.67 | |
on rearrangeDesktopIcons() | |
tell application "Finder" | |
tell icon view options of window of desktop | |
set theArrangement to arrangement | |
set theArrangementString to theArrangement as string | |
if {"not arranged", "«constant ****narr»", "snap to grid", "«constant ****grda»"} does not contain theArrangementString then | |
display alert "\"Rearrange Desktop Icons\" AppleScript says:" message "Cannot rearrange Desktop items, please change Desktop \"Sort by\" to \"None\" or \"Snap to Grid\"." giving up after 10 | |
return | |
end if | |
set theIconSize to icon size | |
set theLabelSize to text size | |
end tell | |
set theDesktopBounds to bounds of window of desktop | |
set theDesktopWidth to item 3 of theDesktopBounds | |
set theDesktopHeight to item 4 of theDesktopBounds | |
-- Retrieve a list of items on the desktop | |
set theDesktopItems to every item of desktop | |
set theContestantOffset to theIconSize / 2 | |
set theSpacing to (theIconSize + theLabelSize + theContestantOffset) * theSpacingFactor | |
set theGuttersX to theSpacing * theGutterXFactor | |
set theGuttersY to theSpacing * theGutterYFactor | |
set theMaxColumns to ((theDesktopWidth - theGuttersX * 2) / theSpacing) as integer | |
set theMaxRows to ((theDesktopHeight - theGuttersY * 2) / theSpacing) as integer | |
set theMaxLocations to theMaxRows * theMaxColumns | |
set x to 1 | |
repeat with a from 1 to length of theDesktopItems | |
set y to a mod theMaxRows | |
if y is 0 then | |
set y to theMaxRows | |
end if | |
if a is greater than theMaxLocations then | |
set desktop position of item a of theDesktopItems to {theGuttersX, theGuttersY} | |
else | |
set desktop position of item a of theDesktopItems to {theGuttersX + (x - 1) * theSpacing, theGuttersY + (y - 1) * theSpacing} | |
end if | |
if a mod theMaxRows is 0 then | |
set x to x + 1 | |
end if | |
end repeat | |
end tell | |
-- Clean up, after moving icons | |
tell application "Finder" to activate | |
tell application "System Events" | |
tell process "Finder" | |
click menu item "Clean Up" of menu "View" of menu bar item "View" of front menu bar | |
end tell | |
end tell | |
end rearrangeDesktopIcons | |
on adding folder items to alias after receiving listOfAlias | |
rearrangeDesktopIcons() | |
end adding folder items to | |
on removing folder items from alias after losing listOfAliasOrText | |
rearrangeDesktopIcons() | |
end removing folder items from | |
rearrangeDesktopIcons() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment