Hello everyone!
This is my first post here so bear with me. I was browsing throughout multiple sites and didnt see any scripts to make a widget in center. Well my "solution" only works for songs, and my code is specifically written for Spotify
it centers the text approximately, and based on some very basic math algorithms.
The bad news is that it needs (or its current version) a whole bar for itself. The way I used it that in global widgets i have a custom now playing which shortens the text if its too long in order to fit, because there are other widgets. If i press on it, it opens the group where only full name now playing exist. If you press on it it goes back. NEED to set background to black. I hope it helps, at least some of you.
Here's the code:
tell application "Spotify" set space to " " set lspace to count of space set a to artist of current track set a1 to count of a set n to name of current track set n1 to count of n set w to a & " - " & n set song to a & " - " & n set c to 0 repeat with s1 from 1 to count of items in song set x to item s1 of song if x is in " ,()&.-" then set c to c + 1 end if end repeat #return c if c > 4 then if a1 < 6 and n1 < 6 then set half to (a1 + n1 + 3) / 2 set d to lspace - half set fix to text 1 thru d of space set l1 to length of fix if l1 + half = 128 then return fix & w else if l1 + half = 128.5 then set fix1 to text 1 thru (d - 1) of space return fix1 & w else if l1 + half = 127.5 then return fix & w end if else set half to (a1 + n1 + 3) / 2 + c set d to lspace - half set fix to text 1 thru d of space set l1 to length of fix if l1 + half = 128 then return fix & w else if l1 + half = 128.5 then set fix1 to text 1 thru (d - 1) of space return fix1 & w else if l1 + half = 127.5 then return fix & w end if end if else if a1 < 6 and n1 < 6 then set half to (a1 + n1 - c) / 2 set d to lspace - half set fix to text 1 thru d of space set l1 to length of fix if l1 + half = 128 then return fix & w else if l1 + half = 128.5 then set fix1 to text 1 thru (d - 1) of space return fix1 & w else if l1 + half = 127.5 then return fix & w end if else set half to (a1 + n1 + 3) / 2 set d to lspace - half set fix to text 1 thru d of space set l1 to length of fix if l1 + half = 128 then return fix & w else if l1 + half = 128.5 then set fix1 to text 1 thru (d - 1) of space return fix1 & w else if l1 + half = 127.5 then return fix & w end if end if end if end tell
It needs some adjustment, and more rules because not every title looks good. I'm still working and setting more 'if's to make it better. Feel free to edit the numbers for your liking Have a nice day!
edited for the code because i am noob at forums