Jump to content

Hans-Pe

Member
  • Posts

    10
  • Joined

  • Last visited

Posts posted by Hans-Pe

  1. To accomplish this, I built an Automator Service, which consist of only one Applescript:

     

    on run {input, parameters}
    
    (* Your script goes here *)
    set htmlout to ""
    tell application "Safari"
    repeat with t in tabs of window 1
    set el_li to "<li><a href=" & URL of t & ">" & name of t & "</a>"
    set htmlout to htmlout & el_li
    end repeat
    set htmlout to "<ul>" & htmlout & "</ul>"
    end tell
    
    set textutil to "| textutil -stdin -inputencoding utf8 -format html -convert rtf -stdout | pbcopy"
    do shell script "echo " & quoted form of htmlout & textutil (* escape erforderlich*)
    
    return input
    end run

     

    Of course you could put this script into an Alfred workflow as well. 

  2. 4 hours ago, deanishe said:

     

    None of those exist on my Catalina system.

    Sorry deanishe,

    I deleted my original post after a few minutes, because I realized the nonsense (too late in the evening) , but you were faster.

    I confused /etc/zshenv with /etc/zprofile:

    • /etc/zshenv is run for all zsh sessions 
    • /etc/zprofile runs only for interactive shells and executes path_helper

    A simple workflow with run script bash or zsh

    echo -n $PATH

    yields

    [Run Script] Passing output '/usr/bin:/bin:/usr/sbin:/sbin'

     and confirms what you wrote already.

     

    I am running BigSur and I have installed miniconda:

     

    ~ % whence -va python3 
    python3 is /Users/xx/miniconda3/bin/python3
    python3 is /usr/bin/python3


     

    ~ % for p in $(whence -a python3)
    for> print "$p is $($p --version)"
    /Users/xx/miniconda3/bin/python3 is Python 3.9.7
    /usr/bin/python3 is Python 3.8.9


     

    So if in an Alfred run script  I code   

    python3 ./some.py

    python 3.8.9 gets called. If I submit the same command in Terminal, python 3.9.7 gets called. 

     

    This is what I or others have to consider if we want to use Python in Alfred.

     

     

  3. The tab groups in Safari didn't excite me, too much clicking with the mouse.
    I reimplemented this feature with a workflow (script filter in Python and Applescript), which I can easily control from the keyboard. As a bonus, I can set per group whether I want to open them normally or with safe browsing. Each  tabgroup is described by a simple txt-file containing its title and its urls. 

     

    Look at it in github. But I have to improve the documentation. 

     

  4. 20 hours ago, deanishe said:

    You can run Automator workflows with the /usr/bin/automator command-line program:


    /usr/bin/automator -i /path/to/input/file /path/to/workflow.workflow

     

    That's it! Thank you!

    In order to feed multiple files into a workflow, automator requests to get the list of file pathes to be piped from stdin separated by newlines (see man). So I added printf in front of automator.

    Bildschirmfoto 2021-09-04 um 13.30.54.png

  5. I built some Quick Actions in Automator (e.g. with pdf actions like "Combine PDF Pages").

     

    I wonder if and how it is possible to reuse them in Alfred and invoke them in Alfred File Actions. I would prefer to invoke them from Alfred's user interfaces instead to have to memorize crazy keyboard shortcuts or to have to ⌃click the file selection in Finder.

     

    I am running BigSur.

    - Hans-Peter

  6. 15 hours ago, deanishe said:

    It's an AppleScript thing. That's clear enough from the fact that it only works if the script is compiled (Script Editor compiles scripts before running them). Also, don't use Run NSAppleScript: it behaves in weird ways, and it's run on Alfred's main thread, so Alfred will freeze while your script is running.

     

    The way you're doing it with the "where" keyword is the right way.

    deanishe,
    you are right. It's an AppleScript thing.

     

    I compared the scpt-files produced with Scripteditor and with osacompile. Same length and they are nearly identical, they differ only in the event code used for property path of document:

     

    Scripteditor generates ppth, which is correct and osacompile generated FTPc, which is property path of class URL, I found a list of event codes in gist.

     

    You objected to my use of "Run NSAppleScript". OK, I merged the two AS now into a single "Run Script", this simplifies the whole workflow and makes it more efficient.

     

    Thanks for your comments
    -Hans-Peter
     

    bbdiff.png

  7. I wrote a workflow which queries System Events for the currently active application. The result is used in a tell block to query the application for the path of the file corresponding to the top window. Finally this path is used to pop up Alfred's file action menue.

     

    Short Snippet to show the principle and describe my question:

    tell application activeApp
         set the_doc to front document
         set the_name to the name of the_doc
         set the_result to path of the_doc 
    end tell

     

    When run outside Alfred, the snippet works as expected. 


    But it throws AppleScript error -1728 when included inside Run NSAppleScript and Run Script (/usr/bin/osascript). The error is thrown at the third set command, that is, I am able to get the front document and its name property, but I fail to access the document's property path.

     

    -1728:„TextEdit“ hat einen Fehler erhalten: „path of document "alfred"“ kann nicht gelesen werden.

     

    Running the script from Sripteditor works fine. Running the compiled AppleScript with osascript from terminal also works fine. Running the AppleScript text with osascript (I think, this is how Alfred is doing it) from terminal yields -1728 as in the Alfred case.

     

    To make it work in a workflow, I have to compile the script with the help of Scripteditor and run the resulting scpt-file with osascript in a shell in Run Script:

    query=$1
    echo -n $(osascript frontfile.scpt "$query")

     

    I provide two workflow-files on Github: 

    1. frontmostdoc.alfredworkflow is the released and working workflow
    2. frontmostdoc-prototype.alfredworkflow shows how I started and demonstrates the issues describes above: keywords "wo" and "ou" are failing, keyword "where" works. 

     

    Is there a bug in osascript or did I run into some kind of restriction in the AppleScript Language

     

    macOS BigSur Version 11.4

    - Hans-Peter

×
×
  • Create New...