Jump to content

Post Notification in the middle of a bash script while loop


Recommended Posts

I have a workflow that is listening for spotify ads (so i can mute them). 

 

nWVa8QviRUSdRUAE6y0ww3zLs6sB9g.png

 

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

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 by dfay
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...