Jump to content

alexcory

Member
  • Posts

    47
  • Joined

  • Last visited

Posts posted by alexcory

  1. You could maybe add a setting called "text expansion key" so people could use other keys too.  I just think tab is super intuitive and it allows it so your snippets don't interfere with other text you might be typing.  Some people may prefer the enter key. Anyway, I will promote the shit out of the text expansion for Alfred if you add this one feature.  Until then I'll have to stick with aText :(

  2. Basically what I want is instead of "auto expanding" what would be nice is to type your keyword, and then hit tab to expand it.

     

    Example: (you type)

    lorem + TAB

    which would equate to

    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

     

  3. Okay, so I thought this through a little more and here's what I've gotten so far.

     

    I need to be able to grab the file path of the current project that I have open.  I thought of a couple different ways to do this.
     
    First of all, at least for me, I only have 2 `workspaces` I used to house all of my projects on my machine.  `htdocs` and `git repositories`.  I'm assuming most developers do the same.  With this in mind, I feel like developers could set their project directories initially which would give me the place to stop when pattern matching in the next step.
     
    I could then use Applescript to grab the current file, match that absolute path with the `projects` in their `workspace` to determine the `current project's directory`.
     
    I've found the following Applescript code from another workflow but being that I'm mostly `php` proficient, I am having trouble passing the output of the Applescript to php.
     
    I know there is a way to just grab the current project directory via Applescript but I can't figure out how.
     
    Could I get a wee bit of help on this please! :)
     
    Also, here are the steps I've thought of to complete this workflow.  Any suggestions / advice on things I might have planned out wrong?
     
    Step 1 (aka: pre-search - initialized by hot key)
    • Settings:
      • Choose whether you want absolute path, or relative path to be default when pasting path in [need help figuring this part out]
      • ie: relative 
    • get path of project directory [i feel like there's a better a better way to do this.  Any way to do it in bash?]
      • path to find: /users/username/path/to/workspace/current_project
      • ideas:
        • have the user initially set their "workspaces" where they usually put their projects (not preferred)
        • grab the path via Applescript for whatever IDE/Text Editor the user is currently in [how do I grab this?]
    • get path of current file
      • path to find: /users/username/path/to/workspace/current_project/views/elements/header.php
      • possible logic 
    // filename: get_path.scpt
    on getPath()
    	-- get path to frontmost document
    	set frontPath to (path to frontmost application as text)
    
    	try
    		tell application (frontPath)
    			try
    				set p to (path of document 1) -- preview uses this style
    			on error
    		set p to (do shell script "ruby -rcgi -e 'print CGI.unescape ARGV[0][7..-1]' " & quoted form of p)
    		if p starts with "localhost" then
    				set p to (file of document 1) -- keynote, pages uses this style
    			end try
    		end tell
    		set p to POSIX path of p
    
    	on error
    
    		-- if all else fails try to get it through system events
    
    		tell application "System Events"
    			set theprocess to the first process whose frontmost is true
    			set thewindow to the value of attribute "AXFocusedWindow" of theprocess
    			set thefile to the value of attribute "AXDocument" of thewindow as string
    		end tell
    		--tell application "System Events" to tell (process 1 where frontmost is true)
    		--	value of attribute "AXDocument" of window 1
    		--end tell
    
    		set p to result
    			set p to (do shell script "ruby -rcgi -e 'print CGI.unescape ARGV[0][9..-1]' " & quoted form of p)
    		end if
    
    	end try
    
    	return p
    end getPath
    
    set p to getPath() of pathscript
    
    -- get parent directory
    do shell script "dirname " & quoted form of p
    return p                                          [What am I doing wrong here?]
    

    // then grabbing the the output of p in the php file

    // filename controller.php
    <?php
    include_once 'get_path.scpt';
    include_once 'Workflows.php';
    $w = new Workflows;
    
    $path = exec('osascript get_path.scpt'); //               [Why do neither of these work? Output: "Parse error: parse error in Command line code on line 1"]
    // $path = passthru("/usr/bin/osascript get_path.scpt"); 
    
    var_dump($path);
    
    ?>
    Step 2 (aka: search)
    • set the search location to current project's directory
    •  
    • get path of queried file
      • ie: /users/username/path/to/workspace/current_project/assets/css/main.cs
    • set paths relative to current project (queried file & current file)
      • ie: remove the "/users/username/path/to/workspace/ 
    • where the current_project names match, stop removing pre-directories
        // aka left with:
        $current_file = '/current_project/views/elements/header.php';
        $queried_file = '/current_project/assets/css/main.css';
    • generate path to be pasted in
      • possible logic 
                       // find how many "../'s" are needed
                       // find the path moving out
                       $dotdot_slashes = count(explode('/', $current_file)) - 1; //don't move up passed current_project
                       $path_out = str_repeat('../', $dotdot_slashes);
    
                       // find the path moving mack in
                       $remove_root_from_queried_file = array_shift(explode('/', $queried_file));
                       $path_in = implode('/', $remove_root_from_queried_file);
    
                       // path to be pasted in
                       $final_path = $path_out . '/' . $path_in;
    • return $final_path

    Any help would be greatly appreciated! :)

  4. So I'm trying to build a workflow where you would initially set whether you wanted to use the absolute path or relative path.

     

    It would then recognize the file you are currently in based off of where you're cursor is (shouldn't matter what IDE you're in), also recognize the project directory that is open.  

     

    You would then be able to fuzzy search (or just regular search) the current project directory for a file you want to include in your current file (ie: a CSS file or something).  When you hit enter, it would then either paste in the relative path or absolute path depending on what your initially set up.

     

    Any help oh how to start this?

  5. This is possible without a workflow. Type 'C' into the search bar at the top left of the Workflows section of the Alfred Preferences. It will search hotkeys along with other fields like "Name" and "Creator"

     

    Image%202014-05-17%20at%209.01.42%20PM.p

     

    Awesome, I just tried this and I guess some other app is overriding the ⌥+C command.  I know this doesn't pertain to you guys, but any advice on how to find out what's causing this?  Maybe like some sort of global "key conflicts" or just  away to see which apps are controlling which hotkeys?  I really appreciate the help by the way!

  6. Another problem based on that shell is how the .git directories are read. I ran into this problem with the workflow processing script on Packal. It was written in PHP, but it just invoked the git commands via shell commands, so here is the relevant github code:

    	// Add all the files
    	$command = "git --git-dir $github/.git --work-tree $github/ add $github/*";
    	exec($command);
    
    	// Commit changes
    	$command = "git --git-dir=$github/.git --work-tree $github/ commit -am 'updated for $bundle version: $version'";
    	exec($command);
    
    	// Push it to the repo
    	$command = "git --git-dir=$github/.git --work-tree $github/ push origin";
    	exec($command);
    

    Obviously, you don't have those variables. The "$github" variable is just the full path to the local git repo.

     

     

     

    It's possible that the discrepancy between your shell environment (set up by .bashrc, .profile etc.) and the one Alfred uses (launchd's environment) is causing the problem.
     
    Where are your git and rsync commands? In /usr/bin or /usr/local/bin?

     

     

    `git` is in both `usr/local/bin` and `usr/bin/`.  The same thing goes for  `rsync`.  At least I was able to see both of them in both directories.

     

    Could you walk through what's going on in those commands?

     

    Does the " --git-dir " portion return the git repository that you're currently selecting?

     

    What does the " --work-tree do?

     

    How does the ".git" work?  The .git part is mostly what's throwing me off I think.

            // Add all the files
    	$command = "git --git-dir $github/.git --work-tree $github/ add $github/*";
    	exec($command);
  7. I'm really not sure, but Alfred doesn't create the browser list himself, it's given to him by OS X, so for some reason, your system has iTerm as a URL handler.

     

    I'm going to move this to the Workflow help section as somebody may be able to help you out as to why!

     

    Cheers,

    Andrew

    Hey Andrew!

     

    I really appreciate the help! Here's what I've tried:

    • turning off the `⌘-Click Opens Filename/URL` setting in iTerm to see if that might help.  
    • You don't think symlinks would have anything do with this do you? (Just curious).  
    • I had to reinstall Alfred when I reformatted my computer a couple weeks back.  (Should I try reinstalling it again?)

    There's been some other problems but I pretty much have them all figured out.  I just haven't had time to figure this one out lately.  Help would be greatly appreciated!

     

    -Alex

     

    (btw, favorite app on my mac. I customized my mac to have the Ubuntu Ambience theme and made Alfred look like Sublime Text's ⌘+⇧+P . see here if you're curoius!)

  8. Whenever I go to open a URL, it opens the default terminal (iTerm) instead of opening the url.

     

    I think I figured out what the problem is though. (partially)

     

    I noticed there were two chrome images on the drop-down as you can see from this image.

     

    Any idea on what might be causing this/how to fix it?

  9. I can't seem to get the php to execute the command I'm giving it in the terminal.

     

    The Problem:

    1. Won't actually perform the task in iTerm

    2. My plugins don't open at vim startup if I start vim like this

    vim ~/path/to/directory
    

    But will work with this

    cd ~/path/to/directory; vim 

    Here's what I put in php:

    $dir = "{query}";
    
    $cmd = "cd " . "$dir" . "; vim";
    
    //echo $cmd;
    //ouputs: cd path/to/proper/directory; vim;
    
    exec("$cmd"); // doesn't even open the terminal
    
    
    $dir = "{query}";
    
    $cmd = "open -a iTerm; cd" . "$dir" . "; vim;";
    // IF TERMINAL SWITCH THE ABOVE iTerm TO Terminal
    
    //echo $cmd;
    //ouputs: cd path/to/proper/directory; vim;
    
    exec("$cmd"); // doesn't even open the terminal
    

    Then I tried running a `terminal command` action with the following in it

    query=“{query}”;
    echo “${query// /\\ }" // because the ~/path/to/foo bar won't work. Needs to be ~/path/to/foo\ bar
    

    I know that last one is not quite right.  I'm still learning bash.  I posted a question on StackOverflow here.

     

    Can anybody help me please!? :)

  10. Double checked to ensure that the escaping options are set correctly? Those will get ya every time...

    I'm pretty sure it's not a good idea to put 

    cd
    

    in there but it made it work properly without opening the terminal every time. It ended up looking like this.

    # -- Step 1: Sync Local Directories --
    
    rsync -avz /path/to/directory1/ ~/path/to/local/git\ repository/for/directory1/;
    # rm -r .DS_Store;
    
    # -- Step 2: Push Changes To Github --
    
    cd ~/path/to/local/git\ repository/for/directory1/;
    git add *;
    git commit -m "{query}";
    git push --all
    

    Is it not good practice to put the cd in there? Can it cause problems or anything?

  11. Why does this work in if I put it in a Terminal Command but not in a Run Script set to /bin/bash/?

    # -- Step 1: Sync Local Directories --
    
    rsync -avz /path/to/directory1/ ~/path/to/local/git\ repository/for/directory1/;
    # rm -r .DS_Store;
    
    # -- Step 2: Push Changes To Github --
    
    ~/path/to/local/git\ repository/for/directory1/; git add *; git commit -m "{query}"; git push --all
    
  12. Thanks Shawn!

     

     

    You have the single/double quotes backward on this line:

            $cmd = 'open -a Finder "$data_dir"';
    
    You probably need a semi-colon on this line:
    $data_subdir = basename( $data_subdir ).PHP_EOL
    

    Depending on what is being returned, you might need equivalence (==) rather than equality (===) on this line:

    if ( $data_subdir === $bundle_id )
    
    You need to use the "{query}" variable from Alfred not the "$query" variable on this line:
    $plist_dir = $query . "/info.plist";
    
    The following line isn't the data directory.
    $data_dir = $w->home() . '/Library/Application\ Support/Alfred\ 2/Workflow\ Data';
    
    If you want to grab all the data directories for Alfred Workflows, then you could just make it easier:
    $data_dirs = scandir($w->data() . "../");
    
    It also might be easier/more reliable to get the bundle id from each plist by doing:
    $cmd =" /usr/libexec/PlistBuddy  -c 'Print :bundleid' '$data_dir/info.plist'";
    $bundle = exec($cmd);
     
    I'm assuming that you want to grab all of the files out a some matching workflow's data directory. If you just want to grab all the files out of the current workflow's workflow directory, then you just need to do:
    $files = scandir(".");
    

     

  13. Could you maybe help me understand a little how this is working.  I'm kind of new to bash and really new to XML (except for HTML ha).  I know some basics but some of these options are confusing me.

     

    - - - - - - - - - demo1: Script Filter - - - - - - - - - -

    cat << CODE                                                               // Is this just taking what is typed into alfred and displaying it? What do

    <?xml version="1.0"?>                                                // the << do?  I know in bash, cat means to just display contents of a file

    <items>                                                                       // does it work the same way here? 

    <item uid="demo" arg="{query}" valid="yes">  

    <title>First Name</title>

    <subtitle>Enter your first name</subtitle>

    <icon>icon.png</icon>

    </item>

    </items>

    CODE                                                                          // How does CODE work? 

     

    - - - - - - - - - demo1: Run Script - - - - - - - - - -

    if [ -f "saved.txt" ]; then               // What does -f do?
    rm saved.txt
    fi

    in=$(echo "{query}" | tr -d "\\")   // How does this work?
                                                      // What does   | tr -d "\\"    do/mean?
    echo "$in" > saved.txt            

     

                                                      // Where is saved.txt located in the file structure?

     

    - - - - - - - - - demo2: Run Script - - - - - - - - - -

    data=$(cat saved.txt)               
    echo "$data {query}"                // Why do we need {query} after $data? I'm confused here.
    rm saved.txt

     

     

  14. In the SO post you are asking how to read the string. You could make a parser or, since its a plist, you could just use the "defaults" command. So...

    defaults read <path to info.plist> "bundleid"
    

    That would read the bundleid in the plist.

    I figured it out! Thanks again!

  15. In the SO post you are asking how to read the string. You could make a parser or, since its a plist, you could just use the "defaults" command. So...

    defaults read <path to info.plist> "bundleid"
    

    That would read the bundleid in the plist.

     

    Sorry for being such a nube.  Just trying to learn! :)

  16. Could anyone tell me why this doesn't work?

     




    <?php
    require_once('workflows.php');
    $w = new Workflows;

    # Navigate to data directory
    $data_dir = $w->home() . '/Library/Application\ Support/Alfred\ 2/Workflow\ Data';

    # lists all the files inside the data directory
    $data_dir = glob("$data_dir" . '/*');

    # grab bundle id from project folder
    $plist_dir = $query . "/info.plist";

    $info_plist = simplexml_load_file( $plist_dir );
    $bundle_id = $info_plist->dict->string;

    // # Grab the data sub-directory's name to compare to the bundle id
    foreach ($data_dir as $data_subdir) {

    // grab the end of the file path (the name of bundle_id)
    $data_subdir = basename($data_subdir).PHP_EOL

        // if name of data directory matches the bundle_id
    if ($data_subdir === $bundle_id) {

            // then open the data directory in Finder
            $cmd = 'open -a Finder "$data_dir"';
            exec("$cmd");
        }
    }


  17. Okay so basically I'm trying to make a workflow that helps people quickly reference the alfred workflow directories super easily.  I made one partially already but now I'm trying to go a little further.

     

    I guess I'm extending the Manage Alfred Extension.  What I am trying to accomplish is instead of hitting function to toggle a workflow on or off, I want to simply open the data directory in finder.

     

    Is there an easier way to grab the individual data paths?  ie: {data} kind of like {query} but it would output the data directory instead of the project folder directory.

     

    I posted this to stack overflow to try and get some help.  Thanks for any help you can give! :D

  18. Alfred Workflow Builder QuickRef

     

    (Download Here)  

     

    (Github) (Packal)

    Description

    Helps locate the files and folders that you most often need to access for building Alfred workflows by listing the files in the order which workflows or data

    directories you most recently used.

     

    This workflow was based of a previous workflow built by Dajun Duan. His workflow can be located here.

     

    Controls

    Enter — Browse in Alfred

    ⌘ Enter — Reveal in Finder

    ⌥ Enter — Open in Sublime Text

     

     

    Type in awf and choose.

     

    7kdo.png

     

    Data Directories

     

    k1ni.png

     

     

    Workflows Directory

     

    es6t.png

  19. Okay so I've been working on this workflow but I was wondering If I we could do a Google Hangout or Skype or something really briefly.  If not, no worries.  I'm just used to web development with PHP so it's harder diving into this.  Basically with Web Dev, I'm able to output stuff to the screen to see if I'm doing things correctly.  

     

    Ie: I say  <?php echo "hello world!" ?> , refresh the page, and then I see hello world.

     

    What I was going to check was to test it out, say... <?php echo $w->path(); ?> to see if it would return the path.  But I don't know were to see the output.  Do you see what I'm saying?

     

    Also, with the exec() command.  Do I just put per say.. a bash script inside it?

     

    ie:

    $data_directory = "path/to/data_directory/";

     

    # Make sure the data directory exists
    // if the directory doesn't exist
    if ( !file_exists( $data_directory ) && !is_dir( $data_directory ) )
    {
         // Make a new directory
         exec( 'cd path/to/; mkdir data_directory/;' );
         exit;
    }

     

    To start it out in the simplest way, do this:

     

    Since you know PHP, use that.

     

    Download a copy of David Ferguson's workflows library (see libraries and helpers thread pinned in this forum). Include that.

     

    Create a workflow with just a script filter for now. In it, have it be bash, and just have the command be `php snippets.php`. Have no argument selected.

     

    Create the snippets.php file in the workflow directory. Include David's workflows.

     

    Start a "first run" function that checks to make sure the data directory exists, and, if not, create it. Make sure that the data directory contains a settings file. If not, create the file and open it in a text editor (just use some exec($cmd) functions to do this). It'll be easiest to have the settings file be some json (so you can use json_decode) with just a user: and key: fields.

     

    Use those and query github to get a list of all of the gists, and bring those back into an array.

     

    Use a foreach statement on each row, make sure that you have use the $key => $value in that statement:

      Do a preg_match on the name of the gist to see if "#snippet" is in the name. If there isn't a match, then unset($gists[$key]); You should then have all of your gists that match the snippet.

     

    Use the add_result (or whatever the object method is) from the workflow library to add all of the results to the workflow object constructed (see how David's library works). Then "echo $w->toxml()"; That should provide you with the feedback. Use the raw URL of the gist as the argument.

     

    Then, try to run the workflow. If you get a list of gists in Alfred, you're on the right track.

     

    Now, go back and change the script filter to have "argument required" in there, and change the command to `php snippets.php {query}`. Now, look into having some fun with $argv processing in the PHP script in order to filter out more results.

     

    Create a new action in Alfred that runs a script.

    Have it be PHP. Then, have the contents akin to something like:

    echo file_get_contents("{query}");

     

    Then, add in a copy to clipboard action in Alfred. For the contents, have it be, simply {query}. Then check the box that says "automatically paste to ...".

     

    That should be it.

  20. Okay so I have this idea that I got from Nettuts+.  It's already a Sublime Text Package.  Here is a Demo of it.

     

    1. I basically want to be able to look up my gists the same way I can with willfarrell's Github Workflow using my username and using a personal access token from github.

     

    2. I want to be able to filter out all the gists that don't have the   #snippet   tag at the end of them.

     

    3. Once I search and find the correct one, I want it to copy it to my clipboard and also paste the gist snippet whatever text editor/IDE/application my cursor is currently in.

     

    Could anyone give me any advice on how to start this project? I really really want to learn and get better at making Alfred workflows so I think this would be a great little project!

     

    I have some experience in PHP, Javascript/jQuery, HTML/CSS, and some with AppleScript but I wouldn't consider myself a heavy hitter in any just yet but I will learn what I need to.  I just need guidance.

     

    Thanks for any advice!!

×
×
  • Create New...