Skip to content

Instantly share code, notes, and snippets.

@fnordfish
Last active March 5, 2021 07:53
Show Gist options
  • Select an option

  • Save fnordfish/fc65b4fcfce548e6aad963c91d70a0dc to your computer and use it in GitHub Desktop.

Select an option

Save fnordfish/fc65b4fcfce548e6aad963c91d70a0dc to your computer and use it in GitHub Desktop.
Run Spotify cache in a RamDisk. Handles quiting and unmounting.
property LookTime : 10 -- interval to check process
property RamDiskSizeMB : 128 -- size of the Ramdisk in MB
on mount()
do shell script "diskutil erasevolume HFS+ 'SpotifyRamDisk' `hdiutil attach -nomount ram://" & (RamDiskSizeMB * 2048) & "`"
end mount
on link()
do shell script "ln -fs '/Volumes/SpotifyRamDisk' ~/Library/Caches/com.spotify.client"
end link
on unmount()
do shell script "hdiutil detach /Volumes/SpotifyRamDisk"
end unmount
on run
try
tell application "Spotify" to quit
unmount()
end try
do shell script "rm -rf ~/Library/Caches/com.spotify.client"
mount()
link()
tell application "Spotify" to activate
end run
on quit
tell application "Spotify" to quit
delay 1.0 -- there need to be a better way to wait until the disk is no longer busy
unmount()
continue quit
end quit
on idle
tell application "System Events"
if (exists application process "Spotify") then
return LookTime -- check again later
end if
end tell
quit
end idle
@fnordfish

Copy link
Copy Markdown
Author

Copy into "Script Editor" and save as "Application" with "Stay open after run handler" option activated

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