kevnk Posted May 25, 2016 Share Posted May 25, 2016 I have a workflow that is listening for spotify ads (so i can mute them). I have a while loop listening. When it finds an ad (a track with < 35 second duration), it sends a notification - but not an alfred style post notification; just the default applescript-like notification. Here's the code: Note: osascript -e "display notification \"Muting ad for $sleepDuration seconds\" with title \"Mute Spotify Ads\"" This is what I'd like to replace with an alfred Post Notification. vol=`osascript -e 'tell application "Spotify" to sound volume as integer'`; while : do state=`osascript -e 'tell application "Spotify" to player state as string'`; sleepDuration=1 if [ $state = "playing" ]; then duration=`osascript -e 'tell application "Spotify" to duration of current track as string'`; duration=$(echo "$duration / 1000" | bc); if [ $duration -le 35 ]; then position=`osascript -e 'tell application "Spotify" to player position as string'`; position=$(echo "$position" | bc); sleepDuration=$(echo "$duration - $position" | bc); osascript -e "tell application \"Spotify\" to set sound volume to 1"; if [ $sleepDuration -le 0 ]; then sleepDuration=1; else osascript -e "display notification \"Muting ad for $sleepDuration seconds\" with title \"Mute Spotify Ads\"" sleep $sleepDuration; osascript -e "tell application \"Spotify\" to set sound volume to $vol"; sleepDuration=1; fi else osascript -e "tell application \"Spotify\" to set sound volume to $vol"; sleepDuration=1; fi sleep $sleepDuration; else break; fi done osascript -e "tell application \"Spotify\" to set sound volume to $vol"; Link to comment
dfay Posted May 25, 2016 Share Posted May 25, 2016 (edited) If I read your intention correctly, you can create a new workflow trigger that does nothing but post a notification, then call that via Applescript instead of using "display notification" It'll look something like tell application "Alfred 3" to run trigger "xxxxx" in workflow "xx.x.x.x.x" with argument xxxx but the workflow trigger object will give you the exact code Edited May 25, 2016 by dfay Link to comment
kevnk Posted May 26, 2016 Author Share Posted May 26, 2016 Awesome! That was helpful. It took me a while to find the "new workflow trigger" you were talking about, but it's Triggers > External and as soon as you create the id, it gives you all the code you need. Thanks so much! dfay 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now