Last active
March 5, 2021 07:53
-
-
Save fnordfish/fc65b4fcfce548e6aad963c91d70a0dc to your computer and use it in GitHub Desktop.
Run Spotify cache in a RamDisk. Handles quiting and unmounting.
This file contains hidden or 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
| 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Copy into "Script Editor" and save as "Application" with "Stay open after run handler" option activated