Jump to content

Help with List Filter action


Recommended Posts

Hi all. I have a workflow that lists tv channels (http links) and then opens the chosen one on OPlayer using the Open URL action. 
7E1A5DC6-E7ED-47EE-B692-0B50D12D2C68.thumb.jpeg.a3ed92dffd79676163b5d7ef2e6c1fae.jpeg
 

2530EEBE-3BD8-4BBC-BB1A-D5AB114CB0A6.thumb.png.2b7ddfe9323575923771581cd9fe5116.png

 

The workflow works seamlessly when I use OPlayer url scheme (oplayer://http://example.com.m3u8) as an argument in List Filter action. However, OPlayer for Mac has a few glitches, so I’d like to start using QuickTime Player in its place. The problem is that I didn’t find the QuickTime’s URL scheme and the only way I found out to send the link to QT is through a script. The script looks like:

open -a "quicktime player"   http://example.com.m3u8.

I tried to use it as an argument but it didn’t work.

60BF06B1-996A-4A19-B971-455CD1252AC8.thumb.jpeg.d2aa6e2c831a2148b24def95134ba234.jpeg
 

So I replaced the Open URL action with the Run Script action and it still not working. 
C199D708-AB70-40AE-92D6-67FA5F2A5C0C.thumb.jpeg.a5cc1d72da7b0977a757af1b9d75ea6e.jpeg

This is the first time I’m trying to make a workflow and also I don’t know a lot about scripting, that’s why I need your help. I know I could do it all with one script, but since my scripting knowledge is limited, I think the structure of actions I’m using (List Filter -> Open URL) is easier for me to understand. 
 

Can anyone help me with this? Can I use a script line as an argument? What action should I use to replace Open URL when the argument is a script line? 


Thank you all in advance! 

Link to comment

You’re on the right track but have a few errors.

  • In the List Filter, have just the URL as argument.
  • In the Run Script, Language has to be /bin/bash or /bin/zsh.
  • In the Run Script, Script has to be open -a 'QuickTime Player' "${1}".
Edited by vitor
Link to comment
20 minutes ago, vitor said:

You’re on the right track but have a few errors.

  • In the List Filter, have just the URL as argument.
  • In the Run Script, Language has to be /bin/bash or /bin/zsh.
  • In the Run Script, Script has to be open -a "QuickTime Player' "${1}".

 

 

Hi Vitor, thanks for answering!

 

So I let just the URL as argument:

image.thumb.png.e3fb32061569699531df1911603cc818.png

 

Then I set the Run Script language to /bin/bash and added the Script open -a "QuickTime Player' "${1}".

image.thumb.png.9718a9b5271e7daea6691928e60bfe2d.png

 

Did I added the Script line in the wrong place? Do I have to delete query=$1 echo -n $query?

Link to comment
Just now, Danilo said:

Do I have to delete query=$1 echo -n $query?

 

Those are unnecessary, yes.

 

The correct code is open -a 'QuickTime Player' "${1}" (I fixed it in the post above too). One of the quotes wasn’t correctly replaced.

Link to comment
3 minutes ago, vitor said:

 

Those are unnecessary, yes.

 

The correct code is open -a 'QuickTime Player' "${1}" (I fixed it in the post above too). One of the quotes wasn’t correctly replaced.

 

I deleted the unnecessary lines and fixed the code:

image.thumb.png.f2e843111e1d5c80f674210ef7dcf33a.png

 

😔 but it still not working:

image.png.a3f0be9b7a0d74f7d0fd04aecda3818f.png

 

The List Filter argument is just a http url.

Link to comment
2 minutes ago, vitor said:

 

Are you sure it’s a URL QuickTime can play?

 

If so, share a smaller version of the Workflow you have and I’ll take a look.

Now it is working!!! I mistyped the script line.

 

I'll complete the workflow with all URL as argument and check it all again to see if it works seamlessly. If it does, then I'll  let you know here.

 

Thank you so much Vitor!! 🙏🏼

Link to comment
11 hours ago, vitor said:

If so, share a smaller version of the Workflow you have and I’ll take a look.

 

Hi Vitor. I just set the Workflow and everything is working seamlessly. The only thing I'd like to change is QuickTime's behavior when it is already playing a URL and I send a new one to it. Instead of closing the current window, it opens a second QT window with the new URL. Is it possible to add something to the Workflow that would close the current QT window and then open the new http URL?

Link to comment
3 minutes ago, Danilo said:

Is it possible to add something to the Workflow that would close the current QT window and then open the new http URL?

 

Try (above the other code) osascript -l JavaScript -e 'Application("QuickTime Player").windows[0].close()'. Or Application("QuickTime Player").quit() to quit it altogether.

Link to comment
1 hour ago, vitor said:

osascript -l JavaScript -e 'Application("QuickTime Player").windows[0].close()'

This one worked, but now when I run the workflow for the first time, QuickTime run and show that "Open File" window and then it open the player window:

1172538677_CapturadeTela2022-06-23s12_09_102.thumb.jpg.49b5e3e4184145ac71fa35fa321b65bc.jpg

856297329_CapturadeTela2022-06-23.thumb.jpg.a752ff1199903ad88e4bc59c4a94b1f9.jpg

 

Is it possible to prevent QT opening the "Open File" window?

Edited by Danilo
Link to comment

Alright, let’s improve the whole script at once with everything you want. Change the language to /usr/bin/osascript (JavaScript) and use this code:

 

function run(argv) {
  const quicktime = Application("QuickTime Player")

  if (quicktime.running()) quicktime.windows().forEach(w => w.close())
  quicktime.openURL(argv[0])
  quicktime.activate()
}

 

That will close all QuickTime windows (not just the current one). If you don’t want QuickTime to be brought to the front, remove quicktime.activate().

Link to comment
6 minutes ago, vitor said:

Alright, let’s improve the whole script at once with everything you want. Change the language to /usr/bin/osascript (JavaScript) and use this code:

 

function run(argv) {
  const quicktime = Application("QuickTime Player")

  if (quicktime.running()) quicktime.windows().forEach(w => w.close())
  quicktime.openURL(argv[0])
  quicktime.activate()
}

 

That will close all QuickTime windows (not just the current one). If you don’t want QuickTime to be brought to the front, remove quicktime.activate().

 

Wow!!! Now it is working like I wanted. The last thing I was trying here was setting the screen position that QT would open, so I added a new line of code: 

Application("QuickTime Player").windows[0].bounds = {"x":739, "y":262, "width":1498, "height":689}

 

However it didn't work. I'd like to resize and centralize QT window. What am I doing wrong?

Link to comment

I understand you’re figuring these out as they work, but if you give a better picture of the whole from the start we arrive at a better solution faster.


Your code works for me, though you can replace Application("QuickTime Player") with quicktime now. To assist further, I’ll need to see the full code as you have it, and a real URL.

Link to comment
20 minutes ago, vitor said:

I understand you’re figuring these out as they work, but if you give a better picture of the whole from the start we arrive at a better solution faster.


Your code works for me, though you can replace Application("QuickTime Player") with quicktime now. To assist further, I’ll need to see the full code as you have it, and a real URL.

 

My code didn't work when the language was set to  /bin/bash, but then I changed the it to /usr/bin/osascript (JavaScript) and replaced Application ("QuickTime Player") with just QuickTime. Now it is working.

 

The only problem is that the coordinates are not right as I thought it was and also after resizing and moving the window QT resizes the window again to the video resolution size.

 

Here's one copy of the Workflow with the full code and a real URL.

https://www.dropbox.com/s/2obcl2am9i0u4fy/Next TV test.alfredworkflow?dl=0

 

 

Link to comment

The resize is happening before the video starts streaming. Tell it to wait until playback starts.

 

function run(argv) {
  const quicktime = Application("QuickTime Player")

  if (quicktime.running()) quicktime.windows().forEach(w => w.close())
  quicktime.activate()

  quicktime.openURL(argv[0])
  while (!quicktime.documents[0].playing()) delay(0.2)
  quicktime.windows[0].bounds = {x: 739, y: 262, width: 1498, height: 689}
}

 

Link to comment
26 minutes ago, vitor said:

The resize is happening before the video starts streaming. Tell it to wait until playback starts.

 

function run(argv) {
  const quicktime = Application("QuickTime Player")

  if (quicktime.running()) quicktime.windows().forEach(w => w.close())
  quicktime.activate()

  quicktime.openURL(argv[0])
  while (!quicktime.documents[0].playing()) delay(0.2)
  quicktime.windows[0].bounds = {x: 739, y: 262, width: 1498, height: 689}
}

 

Now it worked, but that "Open File" window is being shown again when QT start to run.

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...