Help with Opening Spotify and start playlist

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

myran1178
Junior Coder
Posts: 23
Joined: Fri Oct 23, 2020 7:26 am

Help with Opening Spotify and start playlist

Post by myran1178 » Fri Oct 23, 2020 8:17 am

Hello everyone!
I dont know where in this forum this topic should be posted, so move it if it needs to move!
I am new to Macro Scheduler!(downloaded it yesterday. I am new if I havent used it before, with that, I mean I cant remember if I have used MS before!)
Now over to my question!
What I am , trying to do, is a macro that opens Spotify, clicks on a specific playlist in the left sidebar and plays the first song of the playlist, so now I wonder how to do this after I has been worked with it too many hours yesterday!
Help me!
Bye!
Edited 28th Oct 2020 7:55pm cet:
Finally finished my macro!
Last edited by myran1178 on Wed Oct 28, 2020 6:55 pm, edited 1 time in total.

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Help with Opening Spotify and start playlist

Post by Dorian (MJT support) » Fri Oct 23, 2020 10:49 am

Hi Ryan,

I downloaded Spotify so I could see what your challenges may be, and what works and what doesn't.

This is how I built the script at the bottom of this reply :

First I used Run to start Spotify.

Then we wait for the Spotify window to open with WaitWindowOpen, and Wait for a few seconds for the contents to load. There are more intelligent ways of waiting, but we can leave those for another day (see Image Recognition or UIAccessibleList - advanced)

Now we can use the Find Object Wizard to generate the button clicks.

I found that simply clicking the playlist was unsuccessful unless I just ran the UIClick lines straight from the editor with Spotify already open, and that we needed to use UIFocus first, wait for a moment, then click with UIClick.

Thus we end up with :

Code: Select all

//Run Spotify (you'll need to change the path)
run>C:\Users\xb360\AppData\Roaming\Spotify\Spotify.exe

//Wait for spotify to open and wait for contents to load
WaitWindowOpen>Spotify Free
Wait>10

//Focus your playlist (edit this)
UIFocus>{"Spotify Free"},{"PlayList Test"}
Wait>1

//Click on the playlist (edit this) and wait 
UIClick>{"Spotify Free"},{"PlayList Test"}
Wait>5

//Click play
UIClick>{"Spotify Free"},{"PAUSE"}
Yes, we have a Custom Scripting Service. Message me or go here

myran1178
Junior Coder
Posts: 23
Joined: Fri Oct 23, 2020 7:26 am

Re: Help with Opening Spotify and start playlist

Post by myran1178 » Fri Oct 23, 2020 11:28 am

I want it to work even if the bottom player is empty!

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Help with Opening Spotify and start playlist

Post by Dorian (MJT support) » Fri Oct 23, 2020 11:49 am

Not being a Spotify user I really don't know what the bottom player refers to. Hopefully you're able to use my suggestions above as a starting point by familiarising yourself with the wizards and commands I outlined. They're merely suggestions to get you started.
Yes, we have a Custom Scripting Service. Message me or go here

myran1178
Junior Coder
Posts: 23
Joined: Fri Oct 23, 2020 7:26 am

Re:Re:Re: Help with Opening Spotify and start playlist

Post by myran1178 » Fri Oct 23, 2020 12:13 pm

I was talking about this when I said Bottom player!
https://imgur.com/a/shEQjxv
Cant remember the real name of it so I called it the most logical name(the most logical name is Bottom player cause it is located to the bottom!)

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Help with Opening Spotify and start playlist

Post by Dorian (MJT support) » Fri Oct 23, 2020 12:30 pm

Try the Find Object Wizard as mentioned above, and if that fails use Image Recognition.
Yes, we have a Custom Scripting Service. Message me or go here

myran1178
Junior Coder
Posts: 23
Joined: Fri Oct 23, 2020 7:26 am

Re: Help with Opening Spotify and start playlist

Post by myran1178 » Fri Oct 23, 2020 1:11 pm

I like everything of your code except the play section.
I tried to say that I want my macro to play the first song of playlist doesnt matter if bottom player is filled with something else i listened to recently or bottom player is empty. I think your method requires the bottom player
to be not empty cause it plays the most recent song, not the first song of playlist.

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Help with Opening Spotify and start playlist

Post by Dorian (MJT support) » Fri Oct 23, 2020 2:45 pm

Once you've clicked the playlist you should be able to use CTRL-Left Arrow to navigate up the list.

Code: Select all

SetFocus>Spotify Free*
press ctrl
press left *20
release ctrl
You can then press play. Use the Find Object Wizard I mentioned above to generate the code (or use Image Recognition)

Code: Select all

UIClick>{"Spotify Free"},{"Play"}
Yes, we have a Custom Scripting Service. Message me or go here

myran1178
Junior Coder
Posts: 23
Joined: Fri Oct 23, 2020 7:26 am

Re: Help with Opening Spotify and start playlist

Post by myran1178 » Fri Oct 23, 2020 5:52 pm

How to create a message window that displays the name/title of active window?

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Help with Opening Spotify and start playlist

Post by Dorian (MJT support) » Fri Oct 23, 2020 7:20 pm

Check out GetActiveWindow and Messagemodal.
Yes, we have a Custom Scripting Service. Message me or go here

myran1178
Junior Coder
Posts: 23
Joined: Fri Oct 23, 2020 7:26 am

Re: Help with Opening Spotify and start playlist

Post by myran1178 » Sat Oct 24, 2020 7:40 am

I know but I wonder how to use the active window variable in the message!

myran1178
Junior Coder
Posts: 23
Joined: Fri Oct 23, 2020 7:26 am

Re: Help with Opening Spotify and start playlist

Post by myran1178 » Sat Oct 24, 2020 9:17 am

Found it out now!

myran1178
Junior Coder
Posts: 23
Joined: Fri Oct 23, 2020 7:26 am

Re: Help with Opening Spotify and start playlist

Post by myran1178 » Sat Oct 24, 2020 4:43 pm

Help me with the lines that says "needs help":

Code: Select all

//NEEDS HELP WITH CREATING SHORTER AND FASTER MACRO
//đź —SAVING PREVIOUS ACTIVE WINDOW LINES 2-5 DONEđź —
GetActiveWindow>strTitle,nXPos,nYPos,,
Let>FörraFönstret=%strTitle%
GetWindowSize>%FörraFönstret%,nWidth,nHeight
GetWindowPos>%FörraFönstret%,nXPos,nYPos
//đź —OPENING SPOTIFY AND START THE FIRST SONG OF PLAYLIST LINES7-21 DONEđź — 
run>Spotify.exe
WaitWindowOpen>Spotify Premium
Wait>10
UIFocus>{"Spotify Premium"},{"Niall Horan – Flicker (Deluxe)"}
Wait>1
UIClick>{"Spotify Premium"},{"Niall Horan – Flicker (Deluxe)"}
Wait>5
UIFocus>{"Spotify Premium"},{"Niall Horan – Flicker (Deluxe)"}
Wait>1
UIClick>{"Spotify Premium"},{"On The Loose"}
SetFocus>Spotify*
UIClick>{"Spotify Premium"},{"SPELA UPP"}
press ctrl
press left *20
release ctrl
//đź —ASKING ME IF I WANT OR NOT WANT CONTINUE WHAT I DID BEFORE THIS STARTED. IF YES, RE ACTIVATE PREVIOUS ACTIVE WINDOW.
//DONE LINES 24-29đź —
Ask>Vill du fortsätta med det du gjorde innan Spotify?,strResponse
If>%strResponse% = "Yes"
WindowAction>2,Niall Horan - On The Loose
SetFocus>%FörraFönstret%
MoveWindow>%FörraFönstret%,%nXPos%,%nYPos%
ResizeWindow>%FörraFönstret%,%nWidth%,%nHeight%
//đź —IF I CLICKED NO, REACTIVATE SPOTIFY AGAIN AND MAXIMIZE SPOTIFY. NEEDS HELP WITH THIS LINES 31-54đź —
Else
// C:\Users\Miranda\AppData\Local\Temp\msrFBE6.scp
// Recorded on  lördag, oktober 24, 2020, at 05:12 PM

//Recorded Events
Let>WW_TIMEOUT=5
CapsOn
MouseMove>485,749
Wait>1.613
//Clicking on: 
//SnapShotFile>%BMP_DIR%snapshot_32.png
Wait>1.531
LClick
Wait>0.282
//Activating Window: 
//SnapShotFile>%BMP_DIR%snapshot_33.png
WaitWindowOpen>Spotify Premium
MoveWindow>Spotify Premium,486,112
ResizeWindow>Spotify Premium,800,600
Wait>2.937
SetFocus>Niall Horan - On The Loose
MouseMoveRel>1219,127
Wait>8.959
LClick
SCREENSHOT SHOWING SnapShotFile>%BMP_DIR%snapshot_32.png AND SnapShotFile>%BMP_DIR%snapshot_33.png:
https://imgur.com/a/j9m5QNe

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Help with Opening Spotify and start playlist

Post by Dorian (MJT support) » Sat Oct 24, 2020 5:04 pm

If you mean making it faster, simply trim those recorded Waits down near the bottom.

Also this needs editing :

Code: Select all

If>%strResponse%=YES
Yes, we have a Custom Scripting Service. Message me or go here

myran1178
Junior Coder
Posts: 23
Joined: Fri Oct 23, 2020 7:26 am

Re: Help with Opening Spotify and start playlist

Post by myran1178 » Sun Oct 25, 2020 9:00 am

Help me also with the part under the last code comment

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts