Jump to content

Danilo

Member
  • Posts

    17
  • Joined

  • Last visited

Posts posted by Danilo

  1. 1 hour ago, vitor said:

    Again, it doesn’t seem like you need AppleScript at all. You’re just waiting then sending a keypress, use the objects linked above. The code is doing to much given the inputs and outputs. Looks like you could just be:

     

    delay 0.5
    tell application "System Events" to keystroke "u" using {command down, control down}

     

     

    Just got it to work. Thank you again @vitor and sorry for asking again and again, I'm a newby to coding and just started using Alfred.

     

    Here's the Workflow if it interest to anyone. 

     

    https://www.dropbox.com/s/nkq0ini27slp5o7/Apple Music Lyrics.alfredworkflow?dl=0

  2. 1 hour ago, vitor said:

     

    Are you sure that’s the change you made? active tab has to change to current tab, it’s not just the browser’s name.

     

    Yep, here's the current code:

     

    on workflow()
    	
    	--display dialog "workflow()"
    	
    	tell application "Safari"
    		set myurl to URL of current tab of first window
    		set the clipboard to myurl
    	end tell
    	
    	--display dialog myurl
    	
    	tell application "Downie" to activate
    	
    	tell application "System Events" to tell application process "Downie"
    		click menu item "Open URLs..." of menu "File" of menu bar item "File" of menu bar 1
    		click menu item "Paste" of menu "Edit" of menu bar item "Edit" of menu bar 1
    		key code 76 using {command down}
    	end tell
    	
    end workflow
    
    on init(appName)
    	
    	if appIsRunning(appName) then
    		--display dialog "running"
    		workflow()
    	else
    		--display dialog "starting"
    		set appNameAsText to appName as text
    		tell application appNameAsText to activate
    		delay 0.1
    		init(appName)
    	end if
    	
    end init
    
    on appIsRunning(appName)
    	
    	tell application "System Events" to (name of processes) contains appName
    	
    end appIsRunning
    
    init("Downie")

     

  3. On 7/5/2022 at 2:10 PM, vitor said:

    @danillo Open the Run Script and change

     

    tell application "Google Chrome"
    	set myurl to URL of active tab of first window
    	set the clipboard to myurl
    end tell

     

    to

     

    tell application "Safari"
    	set myurl to URL of current tab of first window
    	set the clipboard to myurl
    end tell

     

    If @James Hobson is interested in supporting multiple browsers concurrently, I’ve made a post on how.

     

    It was the first thing I tried here. I don't know why, but it didn't work. I tried using Webkit instead of Safari but it didn't work too.

  4. On 7/5/2022 at 2:17 PM, vitor said:

    I don’t use Music and you’re faking key presses, so I don’t know what the result is supposed to be to test. Without you sharing the Workflow I can’t even tell what input is supposed to be or why there’s parameters.


    Doesn’t seem like you need any code for it. Try making the same with a Delay Utility and Dispatch Key Combo Output.

     

    Take a look ate these two shortcuts:

    https://www.icloud.com/shortcuts/20a3dd5a728041ea85ba93de399d9f04

    https://www.icloud.com/shortcuts/05e5d4172cbe47c586de77c5b2c14a46

     

    Since Alfred runs AppleScripts much master than Shortcuts.app, I just wanted to "convert" these shortcuts into workflows. I tried to create the Workflow using Keyword as Input than I used the Run Script action. 

    https://www.dropbox.com/s/tnue4ex4zmx6rxo/Apple Music.alfredworkflow?dl=0

     

     

  5. I have two Shortcuts that I frequently use to see the lyrics of the current playing track. The first one toggles the Music miniplayer showing the lyrics and the other one shows up the lyrics on the main Music window. I'm trying to convert these shortcuts to alfred workflows but I don't know what am I missing. The workflow structure is Keyword as Input and then Run Script. The codes I'm using are:

     

    1) Show Lyrics on Music miniplayer 

    on run {input, parameters}
    	tell application "System Events"
    		delay 0.5
    		keystroke "m" using {command down, shift down}
    	end tell
    	return input
    end run

     

    2) Show Lyrics on main Music window

    on run {input, parameters}
    	tell application "System Events"
    		delay 0.5
    		keystroke "u" using {command down, control down}
    	end tell
    	return input
    end run

     

    As Shortcuts these codes are working fine, but not as workflows. What am I missing? Can anyone help?

     

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

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

     

     

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

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

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

  11. 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!! 🙏🏼

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

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

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

×
×
  • Create New...