Jump to content

ctwise

Member
  • Posts

    307
  • Joined

  • Last visited

  • Days Won

    23

Posts posted by ctwise

  1. I was trying to turn Mike Walker's url shortener extension into an Alfred 2 Workflow but failed. Anyone else know how to do this? Here is the link to the extension: http://incredimike.com/projects/alfred-gurl/

     

    You would do it like this:

     

    Screenshot_3_14_13_2_27_PM-5.jpg

     

    And the script would look like this:

     

     

    # longURL supplied by user
    $longUrl = "{query}";
     
    # Use commandline curl because it's good at these sort of things
    $resp = `curl --silent https://www.googleapis.com/urlshortener/v1/url -H 'Content-Type: application/json' -d '{"longUrl": "$longUrl"}'`;
     
    # Use JSON extension added in PHP 5.2
    $json = json_decode( $resp );
     
    # Echo out the URL.
    echo $json->id;
  2. Thanks to everyone for their feedback! I like the color picker idea; I'm searching for the best way to implement it and using several of the suggestions that have been posted here.

    A conditional statement within my code feels like the cleanest solution; I was thinking of latching a 'show color picker' item for all script filters before any input is given (so 'rgb', 'hsl', '#', and 'c' without any code input would allow you to use the color picker). I am still deciding how the color should be used; should it be copied to the clipboard, fed back into Alfred, etc.? I'm leaning toward feeding the color back into Alfred, just so you have more control over what is copied.

    Comments are welcome :)

     

    Feed back into Alfred. It lets you pick a color and then the representation.

  3. Is there currently a way to do this and I'm just missing something? For instance, I would like to launch an app via Command F1. Does anyone know how to get the function keys to show up when creating a workflow? Just thought I would check before posting as a feature suggestion. Thanks.

     

    You can also launch System Preferences and go to Keyboard on the Keyboard tab. Then check the 'Use all F1, F2, etc. keys as standard function keys' to have them output F1, etc. by default. But, then you need to hold the 'fn' key when you want the system function, e.g., increase volume, brighten screen, etc.

     

    Since I work in a Java IDE 90% of the day, I use function keys _way_ more then system function keys, so it's a no-brainer switch for me. Your mileage may vary. 

  4. Creating it as two script filters though makes it show as two items if the user hasn't typed a space yet though correct? If they have only typed '#' then it shows two seemingly identical pieces? Granted, the other would disappear as soon as you pressed space but still.. He could easily just add an if statement to check and see IF a value was passed to the function and if not, display the color picker, otherwise, convert the color passed. Unless I'm misunderstanding something... ?

     

    Nope, you're correct. It's just a little simpler.

  5. This is amazing. You win the internets.

     

    Oh, and adding to the color picker code ctwise posted, you could just add a bit of AppleScript to show the color in Alfred:

     

    OUTPUT=$(osascript -e 'tell application "Finder"' -e 'activate' -e 'choose color' -e 'end tell' | ruby -e 'puts "#" + STDIN.read.split(",").map{|y| "%.2x" % [y.to_i>>8]}.join'); printf $OUTPUT | pbcopy; osascript -e 'tell application "Alfred 2"' -e "search \"$OUTPUT\"" -e 'end tell'

    You can paste that code in to Terminal if you want to see it in action.

     

    Yes, that's much better. A little experimentation shows that creating two script filters for '#' - one that requires arguments and one that doesn't allow them works very well. The one without arguments just displays a single entry to launch the color picker and trigger the above script. The other is untouched from the current workflow.

  6. This is excellent, it's almost a complete replacement for Robert Horvath's Hex Color/Picker workflow. That version does one additional thing yours doesn't, it brings up the color picker when '#' is entered without a hex code. Here's the code it uses to either throw up the color picker or just pass on the hex code:

     

     

    if "{query}" == "pick"
        `OUTPUT=$(osascript -e 'tell application "Finder"' -e 'activate' -e 'choose color' -e 'end tell' | ruby -e 'puts "#" + STDIN.read.split(",").map{|y| "%.2x" % [y.to_i>>8]}.join'); printf $OUTPUT | pbcopy`
    else
        print "{query}"
    end
  7. Hello again.  :)

     

    I wonder if someone could help out with a bit of Ruby scripting. I've written a workflow that deletes a list of files selected from Alfred. The problem is with the script; I can't get it to delete the files.

     


     

    ext = "{query}"
     
    fileNames = text.split("/t")
     
    filesDeleted = ""
     
    fileNames.each do  |fileName| 
     
        command = "rm -r " + fileName
     
        system(command)
     
        filesDeleted << fileName
     
    end
     
    print filesDeleted

     
    Everything else works okay apart from the system call. 
     
    Any ideas as to what I've forgotten? ...  :(

     

    You can use the back ticks to run system commands.

     

    `rm -r "#{fileName}"`

     

    Your problem might be spaces in filenames. Hence the double quotes.

  8. Like the suggestion, but doesn't pbcopy / pbpaste only work with text files? 

     

    That said, I tried your suggestion using a workflow with a file action passing arguments to a script of: cat "{query}" | pbcopy

     

    Didn't work with text or other files

     

    Workflow I tried is here: http://sphardy.net/FsKu

     

    Alfred separates filenames with tabs. 'cat' doesn't understand tab separated filenames. The simplest approach is this:

     

     

    echo "{query}" | sed -e 's/ /\\ /g' | xargs cat | pbcopy
     
    Tell Alfred to escape double quotes and nothing else. This pipes the result through 'sed' to escape spaces, then through xargs to split out the arguments to cat.
  9. What variables are you not getting access to? I know some are available because in my PHP utility class that I use, I set paths that include the users home folder in them by grabbing the value of $HOME and saving it into a variable.

     

    See this discussion - http://www.alfredforum.com/topic/433-provide-login-session-option-for-bash-scripts/?hl=environment

     

    The simplest example is PATH. It's there, but it's a truncated path that doesn't include whatever you set in your initialization scripts. If you set things like JAVA_HOME or whatever else, they won't be there either.

     

    This shouldn't be the default behavior, the existing approach is correct. But it would be useful to be able to request a login shell environment when needed.

  10. Just made a little update to this to make it so that you could remove servers from the list.

     

    Just use the srv keyword to get your server list, highlight the server you want to delete, and press cmd+enter to delete it from the server list

     

    Download

     

    Please change line 4 in addserver.php from:

     

     

    $input = explode( " ", $input );
     
    to:
     
    $input = explode( " ", $input, 2 );
     
    UNCs can have spaces in them.
     
     
  11. Btw, I love this idea. Don't know why I haven't thought about making this already as there are several folders I manually navigate to often. Here it is :)

     

    Download

     

    Find a folder in search results or in the file nav, there should be a result action for folders only labeled "Add to Favorites". Select it and the folder will be added to your favorites list.

    Use the 'favs' keyword to see the list of favs. Pressing Enter will open the fav in Finder. Cmd+Enter will browse that folder in Alfred. Ctrl+Enter will delete it from the favs list.

     

    Btw, the fav items are marked as a file item so you can still action them too

     

    Can you use this applescript to open the links? The current approach opens them in Finder, regardless of whether Path Finder is available.

     

     

    on alfred_script(q)
        try
              tell application "Finder"
                    set appname to name of application file id "com.cocoatech.PathFinder"
              end tell
            tell application "Path Finder"
                activate
                select q
            end tell
        on error err_msg number err_num
            tell application "Finder"
                 reveal POSIX file q as text
                activate
            end tell
        end try
    end alfred_script
  12. The file actions only filter by file type, that works well in most situations but not all of them. For example, if I want to add file actions to git folders, my only recourse is to assume all folders are git folders since the file type is 'public.folder'. If it was possible to filter by filename, I could take one more step and filter by type _and_ by name, e.g., directories with names that match '*.git'. Best of all would be the ability to execute a script that indicated whether the file action was applicable. Here's an example of the possible configuration:

     

    Name: Open in SourceTree

    Name: [ ] Accepts multiple files

    Types:

        public.folder

    Files only (optional): false

    Filename pattern (optional): <none>

    Script filter (optional): (bash)

        if [ -f {query}/.git/HEAD ]

        then
            echo true
        else
            echo false
        fi
     
    This would add 'Open in SourceTree' to every directory that included a .git/HEAD file under it.
     
    I'm aware that this has the possibility to be very "heavy" in constructing the list of possible file actions. One way to minimize that heaviness is requiring Types regardless of whether a script is provided, that way the script will only be executed when the appropriate file types are detected.
     
    Lastly, I would like an option to make a filter applicable to only files. There are some actions which are never applicable to directories but applicable to every file, e.g., Path Finder 'Add to Drop Stack' doesn't work on directories.
  13. Say I wanted to type in a keyword in Alfred and it would start up the file browser at /some/specified/directory. How would I go about doing this? Would I need a separate script? My end goal is to type in a keyword say ssd, and that text would be replaced in alfred with /some/specified/directory. 

     

     

    on alfred_script(q)
        tell application "Alfred 2" to search "/some/specified/directory"
    end alfred_script
  14. I collected the various workflows I've posted together on Github (https://github.com/ctwise/alfred-workflows). One or two are new but most have already been posted on this forum.

     

     

    character-palette

    Very simple workflow to display the OS/X Character Palette for selecting obscure characters. Responds to the keyword 'character'.

    Binary download

    create-histlist-task

    Create tasks in the application The Hit List. Task text follows the format:

    <task text> \[% <hit list category>\] \[! <priority>\] \[| <note text>\]


    Responds to the keyword 'ta'.

    Examples:

    ta Do something - Create the task 'Do something' in the inbox
    ta Do something else %work - Create the task 'Do something else' in the Work folder
    ta More work !1 - Create the task 'More work' in the inbox with priority 1
    ta Stuff | Notes about it - Create the task 'Stuff' in the inbox with 'Notes about it' as a note


    Binary download

    date-and-time

    Very simple workflow to display the current date and time, and, optionally, copy it to the clipboard.

    Responds to both keywords 'date' and 'time'.

    Binary download

    google-autocomplete

    This is based almost entirely on David Ferguson's workflow. It is rewritten in Ruby but only makes two small changes: it provides the raw search text as an option if there are no Google search results and it times out the Google search result request.

    Responds to the keyword 'g'.

    Binary download

    kill-process

    Search for and kill a process. This lists all the processes that match the text typed. Selecting a process does a 'kill' on it. Holding down the alt modifier key does a 'kill -9' and holding down the cmd modifier does a 'kill -HUP'.

    Responds to the keyword 'kill'.

    Binary download

    menu-bar-search

    This is based on the workflow by Jeroen van der Neut. It was his excellent idea and he provided the Applescript to extract menu items.

    This workflow lets you control the front-most application by triggering menu actions. The text entered is used to display matching menu items. The change from Jeroen van der Neut's workflow is to cache the menu items.

    This workflow is a work in progress and has rough edges. The first is that caches aren't aged - they're permanent. The second is that menu item names extracted from Applescript don't always match the displayed text, e.g., a menu item might say 'Turn feature off' or 'Turn feature on' based on the feature status but the extracted menu text is 'Toggle feature'. The result is that the menu item can't be activated by the workflow.

    Binary download

    network-info

    This is based on David Ferguson's IP Address workflow. The difference is that it provides interface names and mac address.

    The workflow responds to the keywords 'ip' and 'mac'. For the 'ip' keyword it lists all interfaces and the local IP addresses. It also displays the external IP address. For the 'mac' keyword it lists all interfaces and the local MAC addresses.

    If you select an IP address or MAC address it will be copied to the clipboard. Holding down the cmd modifier key will also paste it in the front-most application.

    Binary download

    recent-documents

    Based on the workflows by Clinton Strong and David Ferguson. The difference is it consolidates the OS/X recent documents list and the Alfred recent documentst list.

    Triggering the workflow lists all of the recent documents. Selecting one will open it in the default application. Holding down the cmd modifier key will reveal it in Path Finder or Finder (depending on whether Path Finder is installed).

    Responds to the keyword 'recent'.

    Binary download

    running-apps

    Lists all of the running OS/X applications (not processes, what OS/X considers as a running app). Selecting one will activate the application. Holding down the alt modifier key will trigger the built-in 'quit' Alfred command.

    Responds to the keyword 'running'.

    Binary download

    search-pubmed

    Searches PubMed at ncbi.nlm.nih.gov. Provides two alternates search modes. The first does a keyword search of PubMed articles. Selecting an article displays the article information. The second uses the PubMed search suggestions. Selecting a suggestion performs a PubMed search using that search text.

    Responds to the keywords 'pubmed' for article searches and 'pubmed2' for search suggestions.

    Binary download

    time-machine

    Simple Time Machine status and control. Shows the Time Machine completion status and provides support to start and stop Time Machine backups.

    Responds to the keywords 'tmac status' to show status, to 'tmac start' to start a Time Machine backup and to 'tmac stop' to stop a Time Machine backup.

    Binary download

    top-processes

    Lists the top processes, aka the command-line 'top'. Selecting a process will activate the 'kill-process' workflow to kill the selected process.

    Binary download

    vmware-control

    Based on the Parallels Control workflow. Provides a mechanism to control VMWare VMs.

    • Keyword 'vm list' lists the knows VMs and their current status. Selecting one copies the VM path to the clipboard.
    • Keyword 'vm ip' lists the IP addresses of running VMs. Selecing one copies the IP address to the clipboard.
    • Keyword 'vm start' lists the stopped VMs. Selecting one starts it.
    • Keyword 'vm stop' lists the running VMs. Selecting one stops it.
    • Keyword 'vm reset' lists the running VMs. Selecting one resets it.
    • Keyword 'vm suspend' lists the running VMs. Selecting one suspends it.
    • Keyword 'vm pause' lists the running VMs. Selecting one pauses it.
    • Keyword 'vm unpause' lists the running VMS. Selecting one unpauses it.
    • Keyword 'vm snapshot' requires a snapshot name and lists the running VMs. Selecting one creates a named snapshot of that VM.
    • Keyword 'vm revert' requires a snapshot name and lists the running VMs. Selecting one reverts to a named snapshot of that VM.

    Binary download

    volume-control

    Simple workflow that provides volume control. Keyword 'max' sets the volume to max. Keyword 'medium' sets the volume to mid-level. Keyword 'mute' mutes the system volume.

    Binary download

×
×
  • Create New...