Skip to content

Instantly share code, notes, and snippets.

@ddaanniiieeelll
Last active May 2, 2020 08:41
Show Gist options
  • Save ddaanniiieeelll/c45c6094d0f5074057421c2d5ac863f2 to your computer and use it in GitHub Desktop.
Save ddaanniiieeelll/c45c6094d0f5074057421c2d5ac863f2 to your computer and use it in GitHub Desktop.
# original script by Frank Grießhammer
# https://gist.github.com/frankrolf/efef92914113c43ab69dd58d42267999
# Distribute all stickies evenly on the main screen, with optional padding
# how many columns?
set num_columns to 5
# how many pixels of padding between the stickies?
set padding to 20
# Find the dimensions of the main screen
# https://stackoverflow.com/questions/1866912/applescript-how-to-get-current-display-resolution
# This has a problem with retina screens
# set {width, height, scale} to words of (do shell script "system_profiler SPDisplaysDataType | awk '/Main Display: Yes/{found=1} /Resolution/{width=$2; height=$4} /Retina/{scale=($2 == \"Yes\" ? 2 : 1)} /^ {8}[^ ]+/{if(found) {exit}; scale=1} END{printf \"%d %d %d\\n\", width, height, scale}'")
set height to 1050
set width to 1680
set total_v_padding to (num_columns + 1) * padding
set s_width to (width - total_v_padding) / num_columns
set toolbar_height to 22
set current_sticky to 0
tell application "Stickies" to activate
tell application "System Events"
tell application process "Stickies"
set num_stickies to number of windows
set num_rows to round (num_stickies / num_columns) rounding up
set total_h_padding to (num_rows + 1) * padding
set s_height to (height - total_h_padding - toolbar_height) / num_rows
repeat with i_c from 0 to num_rows - 1
repeat with i_r from 0 to num_columns - 1
set current_sticky to current_sticky + 1
if current_sticky ≤ num_stickies then
set s_x to (i_r * s_width) + (i_r * padding) + padding
set s_y to (i_c * s_height) + (i_c * padding) + padding + toolbar_height
tell window current_sticky
set position to {s_x, s_y}
set size to {s_width, s_height}
end tell
end if
end repeat
end repeat
end tell
end tell
# end
@ddaanniiieeelll
Copy link
Author

The original script can be found here https://gist.github.com/frankrolf/efef92914113c43ab69dd58d42267999

It didn’t work really well for me with my Retina screen. The most simple and probably not the best solution was to comment out Frank’s original function to find the dimensions of the main screen and instead set width and height manually according to my own settings.

For example:
My MacBook Pro has a Display size of 2560 × 1600 (13,3 inch), but the resolution is what Apples system preferences call "looks like 1680 × 1050".
Using those dimensions for height and width shows the expected results of properly ordered stickies :)

CAVE: This only works on this one screen. If you're using a second screen and want to use the script there as well you have to change the values accordingly. If you’re regularly changing between working from remote on just the Laptop screen and working from an office with a second screen you could think about writing two scripts.

ADD: I exported the script as an app and put it in my user script folder for easy access. If you run the script from the editor everything is fine, for running it as an app I had to comment out the last end statement as it regularly rises an error being unable to be read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment