Jump to content

Bhishan

Member
  • Posts

    146
  • Joined

  • Last visited

Posts posted by Bhishan

  1. I just tried copying contents from right this webpage. It does not work.

    macOS:  catalina MacBook Pro 2017

     

    I got two problems:

    1. This did not copy contents from frontmost webpage (I tried on right this page). Somehow the cmd A is not working ( I do not see any selected text, but I see them when I directly press them in my keyboard though)

     

    2. the output file name is not `hello.txt` instead it wrote {var/fname}.txt   ( I gave that command in bash script at the end of workflow).

     

     

    2021-12-20-10-04-39.png

  2. I was trying to use Key Combo `cmd a` and `cmd c` to copy the contents from the frontmost webpage. But, the command A, key does not work, I do not see the selected text (as we see when we actually press the cmd a on keyboard) and the workflow does not work.

     

    How to use AppleScript for that instead of using `Key Combo`?

     

    # Shared link

    https://github.com/bhishanpdl/Shared/blob/master/Alfred_questions/z mycopy.alfredworkflow?raw=true

     

    # My Workflow

    keyword > delay > Keycombo cmdA > Keycombo cmdC > delay > write

    2021-12-20-08-52-49.png

  3. My attempt:  https://github.com/bhishanpdl/Shared/blob/master/Alfred_questions/aa 05 universal action practice.alfredworkflow

     

    I was trying to do some manipulation on multiline string using Alfred Universal Action. But only single line can be processed. How to process multi-line strings?

     

     

    **I am trying to do following**

     

    ```

    This is item 1.

    This it item 2.

    ```

     

    I am trying to create an Alfred Universal Action that will append user suggested prefix (for example:  “1. “ which will make it list in Markdown).

    How can we do so?

     

    Can we give any prefix to the lines? Such as “1. “,   “</br>” and so on?

     

    Final output will look like:

    ```

    1. This is item 1.

    1. This it item 2.

    ```

  4. I have hundreds of workflows and many many Alfred commands. When I selected some text in text editor and went to Universal Action (cmd opt \),

    there are too many actions to choose from and many of them are completely irrelevant. It would be better if there are less items to choose from.

     

    Suggestion:

    Please add a feature so that we can right click a chosen workflow in Workflows tab of Alfred and turn it on or off to be allowed in Universal Action.

  5. @vitor  The code suggested is much more concise,  I also got another AppleScript solution from stack overflow:

    The problem is solved. You can close the topic.

     

    if running of application "Safari" then
        
        tell application "Safari"
            if the URL of ¬
                the current tab of ¬
                    the front window ¬
                        does not contain missing value then
                set theURL to ¬
                    the URL of ¬
                        the current tab of ¬
                            the front window
            else
                return
            end if
        end tell
        
        if running of application "Google Chrome" then
            
            tell application "Google Chrome"
                set incognitoWindowIDs to ¬
                    the id of every window ¬
                        whose mode is "incognito"
                if incognitoWindowIDs is {} then
                    activate
                    my openNewIncognitoWindow()
                    delay 1
                    set URL of ¬
                        the active tab of ¬
                            the front window to theURL
                else
                    make new tab at end of ¬
                        window id (first item of incognitoWindowIDs) ¬
                            with properties {URL:theURL}
                end if
            end tell
        else
            tell application "Google Chrome"
                activate
                delay 1
                my openNewIncognitoWindow()
                delay 1
                set URL of ¬
                    the active tab of ¬
                        the front window to theURL
            end tell
        end if
        
    end if
    
    on openNewIncognitoWindow()
        tell application "System Events" to ¬
            keystroke "n" using ¬
                {shift down, command down}
    end openNewIncognitoWindow

     

  6. Question: How to get the frontmost url from Safari and open it in Google Chrome Incognito?

     

    So far I was able to get the name of frontmost url. I have also seen another workflow to open in chrome incognito. But, I was struggling to combine two.

    I would truly appreciate if somebody jumps in and give me suggestions.

     

    I am looking for AppleScript that will do the work, if there is AppleScript I will be able to create new Alfred Workflow and use it there.

     

     

    Some references are included below:

     

     

  7. This is one of most useful workflows I have ever seen. But for some reasons the workflow is not working for me.

    Is this workflow still in use (2020 April) ?

     

    I tried following:

    - installed downvid workflow

    - go to youtube and played the url  elephants dream trailer 

    - typed `dv` in alfred

     

    Error for elephants trailer in Chrome

    ======================

    ```

    [11:25:45.071] ERROR: DownMedia[Run Script] WARNING: Unable to extract video title

    ERROR: This video is unavailable.

    ```

     

     

    Error  for elephants dream video in Chrome

    ===================================

    ```

    [11:29:26.551] STDERR: DownMedia[Script Filter] /Users/poudel/Dropbox/Alfred.alfredpreferences/workflows/user.workflow.C7EBB14D-C50D-4512-B984-48E18E507967/get_title_and_url.js: execution error: Error: Error: You need a supported browser as your frontmost app (-2700)

    [11:29:41.478] ERROR: DownMedia[Run Script] WARNING: Unable to extract video title

    ERROR: This video is unavailable.

    ```

     

    Error for safari elephants dream video

    ==================================

    ```

    [11:36:27.797] Logging Started...

    [11:36:43.649] ERROR: DownMedia[Run Script] WARNING: Unable to extract video title

    ERROR: This video is unavailable.

    ```

     

    Specification
    ============

    Google chrome: Version 81.0.4044.92 (Official Build) (64-bit)

    Macos:  catalina 10.15.4

    Alfred:  4.0.9

    Date: Apr 13, 2020

  8. How to search a query using let me search that for you website?

     

    For wikipedia I can use:

    http://www.wikiwand.com/en/{query}   # this works good

     

    For lmgtfy I tried:

    https://lmgtfy.com/{query}   # this does not work

     

    This does not work.

     

    Is there a way we can make alfred web search for lmgtfy?

     

     

    If web search is not possible,  how can it be done using Alfred Workflow?

     

    Help is appreciated.

  9. @vitor

     

    This time:

     

    1. runscript applescript

    ```

    tell application "Finder"    

    set someSource to selection as alias list       

     if someSource = {} then             

    return "Select a file in Finder first"       

     end if         

    set theFile to item 1 of someSource as alias
        return quoted form of the POSIX path of theFile

    end tell

    ```

     

    2. utility transform

    ```

    Transform utitliy trim space

    ```

     

    3. runscript

    ```

    pbcopy < "${1}"

    ```

     

    Error:

    ```

    [10:24:05.982] ERROR: aa 00 copy file contents[Run Script] /Users/poudel/Library/Caches/com.runningwithcrayons.Alfred/Workflow Scripts/B0C62B8C-E0C6-4D51-BEB7-8BB2F90FCCB4: line 1: '/Users/poudel/tmp/try space/a.R': No such file or directory

    ```

     

     

    Update:

    ===========

    I used another replace utitlity and replaced single quote to double quote:

    '/Users/poudel/tmp/try space/a.R' ==> "/Users/poudel/tmp/try space/a.R"

     

    Still, Alfred debugger says:

    [10:28:58.588] ERROR: aa 00 copy file contents[Run Script] /Users/poudel/Library/Caches/com.runningwithcrayons.Alfred/Workflow Scripts/7A7A8F20-F2F9-46BF-9D03-BCECF018944E: line 1: "/Users/poudel/tmp/try space/a.R": No such file or directory

     

    But, there is a file: /Users/poudel/tmp/try space/a.R

     

    In terminal I can type:

    pbcopy < "/Users/poudel/tmp/try space/a.R"

     

    This gives the string: "/Users/poudel/tmp/try space/a.R"

     

    and the command:

    cat "/Users/poudel/tmp/try space/a.R" | pbcopy 

    This gives the actual contents of the file a.R in given directory.

     

    and it works in terminal.

     

  10. @vitor

     

    I used:   javascript

    ```

    try {
      decodeURI(Application('Finder').selection()[0].url()).slice(7)
    } catch(error) {
      error.message
    }

    ```

     

    instead of applescript

    ```

    tell application "Finder"    

    set someSource to selection as alias list       

     if someSource = {} then             

    return "Select a file in Finder first"       

     end if         

    set theFile to item 1 of someSource as alias
        return quoted form of the POSIX path of theFile

    end tell

    ```

     

    and got errror:

    ```

    [09:56:44.050] Logging Started...

    [10:02:46.172] ERROR: aa 00 copy file contents[Run Script] /Users/poudel/Library/Caches/com.runningwithcrayons.Alfred/Workflow Scripts/3E16B543-3ADE-4963-93AE-BC34C6CF3007: line 1: /Users/poudel/tmp/try space/a.md

    : No such file or directory

    ```

     

    still does not work with folder with spaces.

  11. @deanishe

    Thanks a lot for suggestion. My attempt was simpler than given link. I am interested in copy text files (.txt, .py, .md etc), images,pdf other types are not required.

     

    As vitor, suggested creating file action is super easy just pbcopy < "${1}"  works good even for folder with spaces.

    But, I was attempting to create keyword (I already have file action) since it was easier to use and I didnt need to invoke file action trigger on selected file.

    I could simply use usual alfred command (double shift) as like in all other cases.

     

  12. @vitor 

    Thanks for suggestion.

    1. I used keyword to copy file contents of a file because its easier.

    using keyword:   double tap shift on a file, type copy file contents, paste

    using file action: hit cmd \ on a file, search workflow copy file contents, select the workflow, paste  

     

    using keyword saves invoking file action (cmd \) , I can directly use double shift to invoke Alfred command.

     

     

    2. I appreciate   pbcopy < "${1}",  this is nicer than cat "$1" | pbcopy.

     

     

    I already have made file action for file copy, it works with space separated folders, but applescript keyword does not work.

  13. I was trying to create an Alfred  workflow using which I can copy the contents of file without opening the file.

     

    github link of workflow: https://github.com/bhishanpdl/Shared/blob/master/Alfred_questions/2019/aa 00 copy file contents.alfredworkflow?raw=true

     

    Fails when: folder name has space in it.

     

    Commands used:

    1. keyword: copy file contents

    2. Run script with osascript

    ```

    tell application "Finder"    

        set someSource to selection as alias list         

            if someSource = {} then             

                return "Select a file in Finder first"         

            end if         

            set theFile to item 1 of someSource as alias
      return quoted form of the POSIX path of theFile end tell

     

    ```

     

    First I had only "return  the POSIX path of theFile" then I changed it to "return quoted form of the POSIX path of theFile". It still does not work.

     

    3. Run script

    ```

    cat "$1" | pbcopy

    ```

     

    This workflow does not work. I googled and found how to get the path of selected item in Finder but could not find how to copy file contents to clipboard.

     

    How can this workflow be fixed so that it works for SPACE separated folders?

     

     

    Example of debug:

    ```

    20:30:00.162] STDERR: aa 00 copy file contents[Run Script] cat: '/Users/poudel/tmp/try space/a.md'

    : No such file or directory

     

    ```

  14. I was trying to make a workflow to go one step up in jupyter notebook.

     

    When I print the output to the LARGE FONT the output is correct, I can paste the output to the Google Chrome and it works correctly.

    But when I use OPEN URL object, it opens the blank tab.

     

    I tried many times still it only opens the blank url.

     

    I have shared the workflow in github: https://github.com/bhishanpdl/Shared/blob/master/Alfred_questions/Jupyter Up.alfredworkflow?raw=true

     

    Question
    ----------------

    How to make the workflow open the current jupyter notebook running in Google Chrome open a new tab with one step up ?

     

    Note: I have used too many Alfred objects, I was also wondering how can I do it only the Applescript workflow.

    Since I am unfamiliar with Applescript, I pipe the output of applescript to bash and then do all the work in python. If it can be done in applescript, instead of too many alfred objects

    it could be done in one or two objects.

     

    Thanks in advance. 

  15. @deanishe   Thanks for the suggestion.

    Now I can paste the last part of the list and also hit "shift-enter". But still I am sure how to make this in a for loop so that it works for all the parts of the list.

     

    Example:

    print(3)
    # comment
    print(5)

    I copied this text to the clipboard and ran my updated workflow: https://github.com/bhishanpdl/Shared/blob/master/Alfred_questions/a a a split the imports updated.alfredworkflow?raw=true

     

    It gives:

    """

    # some comment
    print(5)

    """

    And also hits "shift enter" (this means goes to next cell in jupyter notebook).

     

    How to make this work for all the list components like this:

     

    1. print first part of split of #

    print(3)

     

    2. hit shift-return 

    This goes to downward cell in jupyter notebook

     

    3. again paste next part of # split

    # some comment
    print(5)

     

    4. again hit keybord "shift-enter"

    this creates new cell in jupyter notebook

     

     

     

    I am not sure how to create External Triggers for this workflow.

    Help is much appreciated. Thanks.

     

  16. Apologies for unclear question.

     

    Here is what I am trying to achieve:

    1.  Lets say I have a list   mylist =  ["#hello", "#world"] obtained from clipboard which in fact contain arbitrary number of elements.

    2. print #hello  to given app and simulate keystroke cmd + enter

    3. print #world to given app and simulate keystroke cmd+enter

     

    If I already know how much elements in list, I can append alfred workflow object "output > keyboard combination" one by one, but I don't know how many elements are 

    in the list and I want to hit keyboard keys cmd+enter after pasting list elements each time.

     

    The os.system("...") command is just the pseudocode,  obviously it does not work.

  17. I have long string of python imports like this:

     

    # usual imports
    import os
    import sys
    
    
    
    # data manipulation
    import numpy as np
    import pandas as pd

     

     

    While working in Jupyter notebook, when I paste something and hit "cmd enter" it will go to next cell and again we can do paste and hit enter.

     

    How can it be done using Alfred?

     

    I have tried this so far:

    import sys
    import os
    import time
    
    s = """
    # usual imports
    import os
    import sys
    
    # data manipulation
    import numpy as np
    import pandas as pd
    """
    
    lst = s.lstrip().rstrip().split('\n#')
    
    
    for i,l in enumerate(lst):
        x = l if i == 0 else '#'+l
        os.system("tell application system events to keystroke v holding command")
        time.sleep(0.2)
        os.system("tell application system events to keystroke return holding command")

     

    This is a starting idea, but the code is not working. Maybe I have something to change in applescript or follow other ideas.

    My question to experts is how to make it viable?

     

    I have shared my primary workflow here:  https://github.com/bhishanpdl/Shared/blob/master/Alfred_questions/a a a split the imports.alfredworkflow?raw=true

  18. Thanks for the suggestion of use of json. I appreciate it.

     

    What I meant by spending hours is, I saw your solution, but tried to make it work in python alone and it took me hours.

     

    There is much to absorb in the given tutorial (python, applescript and so many things) but not a single stand alone python workflow which is kind of complete.

    So, I tried to implement the workflow in python borrowing all the ideas from that link. The link is helpful but its broad and takes some time to filter out.

     

  19. I was wondering how to create multiple argument variable using python.

    After hours of googling I found this link:

     https://www.deanishe.net/post/2018/10/workflow/environment-variables-in-alfred/

     

    and I figured out myself.

     

    # Create env variables

    ```python

     

    import sys

    s = "apple banana; car truck"
    lst = s.split(';')

    a = lst[0]
    b = lst[1]


    myjson = """
    {"alfredworkflow": {
        "arg": "",
        "variables": {"a": "%s",
                      "b": "%s"
                     }
       }
    }
    """ % (a,b)

    myjson = myjson.strip()

    sys.stdout.write(myjson)

    ```

     

    #  Use env variables

    ```python

    import sys,os

    arg1 = os.getenv('b')

    changed = arg1 + ' called from another object'

    sys.stdout.write(changed)

    ```

×
×
  • Create New...