Skip to content

Commit

Permalink
chore: bring applescript back
Browse files Browse the repository at this point in the history
  • Loading branch information
rxri committed Jul 21, 2024
1 parent 067e43a commit 08258f7
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 8 deletions.
16 changes: 8 additions & 8 deletions build/macos/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
set -e

mkdir Volume && mkdir -p bin
osacompile -x -o Volume/Spicetify.app main.applescript
rm Volume/Spicetify.app/Contents/Resources/applet.icns
cp installer/AppIcon.icns Volume/Spicetify.app/Contents/Resources/AppIcon.icns
lipo -create -output bin/spicetify ../../artifacts/spicetify-amd64 ../../artifacts/spicetify-arm64 && echo "Built universal binary"

# Build the helper app with xcode
git clone https://github.com/rxri/spicetify-macos-helper.git
cd spicetify-macos-helper
cp -r ../bin spicetify/bin
sudo xcode-select -s /Applications/Xcode_15.4.app/Contents/Developer
xcodebuild -project spicetify.xcodeproj -scheme spicetify -configuration Release build SYMROOT="$(pwd)/build"
cp -r build/Release/spicetify.app ../Volume/Spicetify.app
cd ..
mkdir -p Volume/Spicetify.app/Contents/MacOS/bin
cp bin/spicetify Volume/Spicetify.app/Contents/MacOS/bin/spicetify
plutil -replace CFBundleName -string "Spicetify" Volume/Spicetify.app/Contents/Info.plist
plutil -replace CFBundleIconFile -string AppIcon.icns Volume/Spicetify.app/Contents/Info.plist
plutil -replace CFBundleURLTypes -xml '<array><dict><key>CFBundleURLName</key><string>Spicetify</string><key>CFBundleURLSchemes</key><array><string>spicetify</string></array></dict></array>' Volume/Spicetify.app/Contents/Info.plist

codesign --deep --force --sign - --timestamp=none Volume/Spicetify.app

Expand Down
85 changes: 85 additions & 0 deletions build/macos/main.applescript
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
on ensureLineInFileIfExists(filePath, lineToAdd)
set ok to false
try
set fileAlias to POSIX file filePath as alias
local fileDescriptor
set fileDescriptor to open for access fileAlias with write permission
try
set lns to paragraphs of (read fileDescriptor)
repeat with ln in lns
if ln is lineToAdd then
set ok to true
exit repeat
end if
end repeat
if ok is false then
write return & lineToAdd & return to fileDescriptor starting at eof
set ok to true
end if
end try
close access fileDescriptor
end try
return ok
end findLineInFile

on addLineToShellConfigs(lineToAdd)
set homeFolder to POSIX path of (path to home folder)
set configFiles to {homeFolder & ".bash_profile", homeFolder & ".zshrc"}

repeat with configFile in configFiles
ensureLineInFileIfExists(configFile, lineToAdd)
end repeat
end addLineToShellConfigs

on launchAgentExists(agentName)
try
do shell script "launchctl list | grep " & quoted form of agentName
return true
on error
return false
end try
end launchAgentExists

on createLaunchAgent(plistPath, agentName, binPath)
set plistPathQ to quoted form of plistPath
do shell script "plutil -create xml1 " & plistPathQ
do shell script "plutil -insert Label -string " & quoted form of launchAgentName & " " & plistPathQ
do shell script "plutil -insert ProgramArguments -array -string " & quoted form of binPath & " -string daemon " & plistPathQ
do shell script "plutil -insert RunAtLoad -bool true " & plistPathQ
end createLaunchAgent

on setupEnvironment(binFolder, binPath, launchAgentName)
set homeFolder to POSIX path of (path to home folder)

set exportString to "export PATH=" & quote & binFolder & ":$PATH" & quote & " # Added by Spicetify"
addLineToShellConfigs(exportString)

set launchAgentsFolder to homeFolder & "Library/LaunchAgents/"
set plistPath to launchAgentsFolder & launchAgentName & ".plist"
if not launchAgentExists(launchAgentName) then
createLaunchAgent(plistPath, launchAgentName, binPath)
do shell script "launchctl load -w " & quoted form of plistPath
do shell script quoted form of binPath & " init"
end if
end setupEnvironment

on open location input
set dirname to POSIX path of (path to me)
set binFolder to dirname & "Contents/MacOS/bin/"
set binPath to binFolder & "spicetify"

do shell script (quoted form of binPath) & " protocol " & (quoted form of input)
end open location

on run
set dirname to POSIX path of (path to me)
set binFolder to dirname & "Contents/MacOS/bin/"
set binPath to binFolder & "spicetify"

setupEnvironment(binFolder, binPath, "app.spicetify.daemon")

tell application "Terminal"
activate
do script quoted form of binPath
end tell
end run

0 comments on commit 08258f7

Please sign in to comment.