Last active
May 7, 2020 22:00
-
-
Save frankrolf/efef92914113c43ab69dd58d42267999 to your computer and use it in GitHub Desktop.
Applescript: distribute all stickies evenly on the main screen, with optional padding
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
# Distribute all stickies evenly on the main screen, with optional padding | |
# how many columns? | |
set num_columns to 7 | |
# 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 | |
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 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 |
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
# Randomize stickies colors | |
tell application "Stickies" to activate | |
tell application "System Events" | |
tell process "Stickies" | |
set num_stickies to number of windows | |
set colors_list to {"Blue", "Gray", "Pink", "Yellow", "Green", "Purple"} | |
repeat with i from 1 to num_stickies | |
set rand_color to some item of colors_list | |
tell window i | |
# this is the dumbest way I’ve ever iterated | |
keystroke "`" using command down | |
end tell | |
click menu item rand_color of menu "Color" of menu bar 1 | |
end repeat | |
end tell | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment