Highlights of my current Touch Bar present
Hey,
I want to share the highlights of my currents TB present. Primary it contains stuff from GoldenChaos and AquaTouch, but I added a few useful and cool new features.
A few days ago I rediscovered the possibility of manipulate the TB with BTT. I use BTT every day for trackpad and keyboard shortcuts, but my TB present was quite old and the last GoldenChaos version was from December 2017 or something... So I spend the last 3 days to change my present completely and optimised things for my own workflow.
Please feel free to make any suggestions and improvements for my scripts!
Add Current Song to Specific Spotify Playlist
Definitely my personal gem. Especially the story behind the coding... I'm not that into python and it took me almost a whole day to get things work correctly. There are two scripts for this kind of service needed. It now takes place in the "Now Playing Actions" from GoldenChaos.
I only enumerate my Playlists. This is what it looks like:
AppleScript
tell application "Spotify"
set currentTrackID to id of current track as string
--- insert ID of your playlist ---
set playlistID to "PLAYLIST_ID" as string
tell application "Terminal"
--- insert path of python script ---
do script "python -I 'PATH_TO_FILE' " & playlistID & " " & currentTrackID & " " in window 1
--- COMMENT FOLLOWING LINES AT FIRST RUN ---
do script "quit()" in window 1
delay 0.5
quit
--- --- ---
end tell
end tell
PythonScript
import pprint
import sys
import spotipy
import spotipy.util as util
#export SPOTIPY_CLIENT_ID='MY_CLIENT_ID'
#export SPOTIPY_CLIENT_SECRET='MY_CLIENT_SECRET'
#export SPOTIPY_REDIRECT_URI='http://localhost'
#if len(sys.argv) > 3:
username = "lowrents.d"
playlist_id = sys.argv[1]
track_ids = [sys.argv[2]]
print("Playlist: " + playlist_id)
print("Tracks:")
for p in track_ids:
print p
#print sys.argv[0]
#print sys.argv[1]
#else:
#print("Usage: %s username playlist_id track_id ..." % (sys.argv[0],))
#sys.exit()
scope = 'playlist-modify-public'
token = util.prompt_for_user_token(username,scope,client_id='MY_CLIENT_ID',client_secret='MY_CLIENT_SECRET',redirect_uri='http://localhost')
if token:
sp = spotipy.Spotify(auth=token)
sp.trace = False
results = sp.user_playlist_add_tracks(username, playlist_id, track_ids)
print(results)
print("done!")
else:
print("Can't get token for", username)
os._exit(0)
You have to create a new ClientID and a developer account: https://developer.spotify.com/dashboard/applications
For the first run you have to comment some lines in the AppleScript! There is some interaction needed at the Terminal. I'm not sure if there is some special handle for the python script when it runs for the first time. This is the only function wich a set up almost 2 years ago. Hope this won't be a big hassle. Please let me know if there are any problems.
Finder Dual Pane
I used to work with two open finder windows side by side, when I clean up my Desktop and Downloads folder. This helps me to arrange the windows. It also respects if the dock is hidden.
AppleScript
tell application "System Events"
if autohide of dock preferences is false then
tell process "Dock"
set dock_dimensions to size in list 1
set dock_height to item 2 of dock_dimensions
end tell
else
set dock_height to 0
end if
end tell
tell application "Finder"
activate
if exists window 1 then
set the collapsed of windows to false
if not (exists window 2) then
tell application "System Events"
keystroke "n" using {command down}
end tell
end if
else
tell application "System Events"
keystroke "n" using {command down}
keystroke "n" using {command down}
end tell
end if
set screen_resolution to bounds of window of desktop
set screen_width to item 3 of screen_resolution
set screen_height to item 4 of screen_resolution
set left_bound to 0
set right_bound to screen_width / 2
set bottom_bound to screen_height - dock_height
set top_bound to 22 (* for the menu bar *)
set the bounds of the first window to {left_bound, top_bound, right_bound, bottom_bound}
set the bounds of the second window to {right_bound, top_bound, screen_width, bottom_bound}
end tell
There is one thing to improve, perhaps someone can help:
If a Finder window open on an other desktop that I'm working on, it won't gather the windows. It ended up with two half-screen windows on two different desktops. I didn't find any solution for changing the desktop of an active window...
Sleep Button
My own improved sleep button: it warns me when it gets clicked (to avoid missklicks). Now I have 2 seconds to react before it starts the screensaver by default (great pleasure in combination with Aerial
AppleScript
set theDialogText to "going to sleep..."
display dialog theDialogText buttons {"nope"} default button "nope" cancel button "nope" giving up after 2
if gave up of result = true then
tell application "System Events"
start current screen saver
end tell
end if
MacStats
Basically it was only copy paste the best thing of several scripts. Do you have any Ideas for a second line of the GPU stats. I can't find any command for display the current GPU load oder VRAM usage...Here is what it looks like:
Also mind the the assigned actions!
macStats_lowrents.bttpreset (95.6 KB)
Add custom Tags
The last thing I would love to share drove me crazy last night. In the end I was more than happy that everything runs as it should, but I think there are a few things to improve... I'm not that good to handle stings.
But first there is a general question @Andreas_Hegenberg:
I tried to rebuild the apple-like tag menu, but it wasn't possible. Can BTT only use 33px (or was ist 35px) of the TB instead of the whole hight? Comparing these two screenshots may clarify my confusion:
BTT
Apple TB
This is the code for tagging the current selected finder file:
AppleScript
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use framework "Foundation"
on addTagToPath(theTag, thePath)
set theURL to current application's NSURL's fileURLWithPath:thePath
set {success, tagArray, theError} to theURL's getResourceValue:(specifier) forKey:(current application's NSURLTagNamesKey) |error|:(specifier)
if theError is not missing value then error theError's localizedDescription() as text
if tagArray is not missing value and (tagArray's containsObject:theTag) as boolean is true then return
if tagArray is missing value then set tagArray to current application's NSMutableArray's array()
tagArray's addObject:theTag
set {success, theError} to theURL's setResourceValue:tagArray forKey:(current application's NSURLTagNamesKey) |error|:(specifier)
if theError is not missing value then error theError's localizedDescription() as text
end addTagToPath
tell application "Finder"
set finderSelList to selection as alias list
set finderSelList to finderSelList as text
--- Here I have to cut out the name of my disk which is "MacHD" ---
--- maybe you have to change the number to match your case ---
set finderSelList to text 7 thru -1 of (get text of finderSelList)
set finderSelList to do shell script "sed 's|" & quoted form of ":" & "|" & quoted form of "/" & "|g' <<< " & quoted form of finderSelList
end tell
try
--insert TAG NAME--
addTagToPath("TAG_NAME", "/" & finderSelList)
on error e
log e
end try
Unfortunately I don't understand the 'edit string' things (especially the terminal stuff) good enough for shorten and improve this script. Especially a more automatic string editing would be nice, but my skills are not sufficient.
Thanks for tips and suggestions!