Danilo Posted June 23, 2022 Posted June 23, 2022 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. 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. So I replaced the Open URL action with the Run Script action and it still not working. 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!
vitor Posted June 23, 2022 Posted June 23, 2022 (edited) 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 June 23, 2022 by vitor
Danilo Posted June 23, 2022 Author Posted June 23, 2022 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: Then I set the Run Script language to /bin/bash and added the Script open -a "QuickTime Player' "${1}". Did I added the Script line in the wrong place? Do I have to delete query=$1 echo -n $query?
vitor Posted June 23, 2022 Posted June 23, 2022 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.
Danilo Posted June 23, 2022 Author Posted June 23, 2022 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: 😔 but it still not working: The List Filter argument is just a http url.
vitor Posted June 23, 2022 Posted June 23, 2022 5 minutes ago, Danilo said: The List Filter argument is just a http url. 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.
Danilo Posted June 23, 2022 Author Posted June 23, 2022 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!! 🙏🏼
Danilo Posted June 23, 2022 Author Posted June 23, 2022 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?
vitor Posted June 23, 2022 Posted June 23, 2022 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.
Danilo Posted June 23, 2022 Author Posted June 23, 2022 (edited) 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: Is it possible to prevent QT opening the "Open File" window? Edited June 23, 2022 by Danilo
vitor Posted June 23, 2022 Posted June 23, 2022 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().
Danilo Posted June 23, 2022 Author Posted June 23, 2022 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?
vitor Posted June 23, 2022 Posted June 23, 2022 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.
Danilo Posted June 23, 2022 Author Posted June 23, 2022 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
vitor Posted June 23, 2022 Posted June 23, 2022 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} }
Danilo Posted June 23, 2022 Author Posted June 23, 2022 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.
Danilo Posted June 24, 2022 Author Posted June 24, 2022 (edited) Vitor what code should I add if instead of wait then resize I wanted to just open the video in PiP mode? I found that script in the link below but i dont know how to add it to my code. https://gist.github.com/danielrotaermel/201f549d5755ea886eb78bb660133722 Edited June 24, 2022 by Danilo
vitor Posted June 24, 2022 Posted June 24, 2022 That is for Safari. QuickTime Player doesn’t provide a programatic way to enter PiP.
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