Jump to content

dfay

Member
  • Posts

    1,054
  • Joined

  • Last visited

  • Days Won

    62

Posts posted by dfay

  1. Here's a revised version that works great for me.  The only issue is that you need to hard-code a default directory for your TaskPaper files, which may not work with the way you work....  I keep all mine in a single directory in Dropbox so it works for me.  Since Spotlight is now only searching a single directory, rather than the entire user home space, it's basically instantaneous.

     

    (BTW thanks to Gianni for writing nice self-documenting code that was v. easy to debug & modify :) )

    -- Releas version: 1.1.1
    -- Developed by Gianni Rondini
    -- more info at dropbyte.tumblr.com
    -- send bug and fix requests to
    -- giannivt [at] gmail [dot] com
    
    on alfred_script(evTest)
    set tpdir to "~/Dropbox/TaskPaper"
    set doc to ""
    set prj to ""
    set todo to ""
    set subSep to " sub "
    set inSep to " # "
    set noDoc to 0
    set noPrj to 0
    
    if evTest contains subSep then
    	if evTest contains inSep then -- checking specific document
    		set text item delimiters to inSep
    		set prj_h to text item 1 of evTest
    		set doc to text item 2 of evTest --saving document name
    		set text item delimiters to subSep
    		set prj to text item 2 of prj_h --saving project name
    		set todo to text item 1 of prj_h --saving todo
    	else
    		set text item delimiters to subSep
    		set prj to text item 2 of evTest --saving project name
    		set todo to text item 1 of evTest --saving todo
    		set doc to "toSave" --saving document name
    		set noDoc to 1
    	end if
    else
    	if evTest contains inSep then -- checking specific document
    		set text item delimiters to inSep
    		set todo to text item 1 of evTest --saving todo
    		set doc to text item 2 of evTest --saving document name
    		set prj to "Inbox" --saving project name
    		set noPrj to 1
    	else
    		set prj to "Inbox"
    		set doc to "toSave"
    		set todo to evTest
    		set noDoc to 1
    		set noPrj to 1
    	end if
    end if
    
    if (doc as text) contains " " then
    	set AppleScript's text item delimiters to " "
    	set newText to text items of doc
    	set AppleScript's text item delimiters to "\\ "
    	set doc to newText as text
    end if
    
    tell application "TaskPaper"
    	activate
    	if noDoc is equal to 0 then
    		set p to do shell script "mdfind -onlyin " & tpdir & " \"kMDItemFSName=='" & doc & ".taskpaper'\""
    		if (p as text) contains return then
    			set Applescript's text item delimiters to return
    			set lista to text items of p
    			set p to {choose from list lista}
    		end if
    			
    		if p is not equal to "" then
    			open p
    		else
    			display dialog "Error: " & quote & doc & quote & " file does not exist!" with icon 1 buttons {"Cancel"}
    			return
    		end if
    	else
    		make new document with properties {name:doc}
    		tell front document
    			delete entries
    		end tell
    	end if
    	
    	tell front document
    		if not (exists project named prj) then
    			make new project with properties {name:prj} at front of projects
    		end if
    		tell project named prj
    			make new entry with properties {text line:todo}
    		end tell
    	end tell
    end tell
    end alfred_script 
  2. So I just tried both of the above commands in Applescript Editor.

     

     

    set p to do shell script "find ~ -iname work.taskpaper"

    returns an error in AppleScript Editor, presumably from the Permission denied messages from trying to find in savedState files in the Library.

     

     

    set p to do shell script "mdfind -onlyin ~ \"kMDItemFSName=='work.taskpaper'\""

    returns the desired file, without any error messages.

     

    When I add the second line back to the original workflow as

     

    set p to do shell script "mdfind -onlyin ~ \"kMDItemFSName=='" & doc & ".taskpaper'\""

     

    it still takes a long time (not quite as long as using find, but more than a minute) but does eventually add the item to the desired taskpaper file.  So the question now is, is it really necessary to search ~ or can we restrict the search and get more speed?

  3. Ok....the multi-minute wait sees to be because of the line

     

    set p to do shell script "find ~ -iname " & doc & ".taskpaper"

     

    I just ran the shell script in terminal and it takes two minutes to run.  And because it searches the entire home directory, it's trying to go into the Library folder and getting 15-20 lines ending in Permission denied tagged on the end.

     

    Is there a faster way of doing this search?  Yes, with spotlight (mdfind) instead of find.

     

    >time find ~ -iname work.taskpaper

     

    ...
    real 2m16.608s
    user 0m0.465s
    sys 0m3.211s

     

    >time mdfind -onlyin ~ "kMDItemFSName=='work.taskpaper'"

     

    real 2m9.366s
    user 0m0.007s
    sys 0m0.006s

     

    user & sys time are way faster (which makes sense since Spotlight is caching all the info. that find is discovering afresh).  Moreover using Spotlight only returns the desired file, rather than the desired file plus a whole bunch of Permission denied lines.

     

    I don't have time to work on this further right now but it seems pretty clear that the delay (at least - and possibly the error) is related to the do shell script... line in the code above.

     

    D

  4. Hmmm....this was working great until this morning...now every search is resulting in an error - but the error message includes a doi URL that works fine when copied and pasted.  I'm wondering if there was a change in the doi API that broke the workflow?

     

     Here's an example of what's returned if I use the "copy formatted reference" command:

     

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
     
    <html>
    <head>
    <title>DOI Naming Authority [http:] Not Found</title>
    </head>
    <body bgcolor="#ffffff">
     
    <table border="0" width="680" cellspacing="2" cellpadding="2">
    <colgroup> <col width="10%"> <col width="90%"> </colgroup>
    <tr>
    <td align="center" colspan="2">
    <img src="http://www.doi.org/images/banner2.gif" alt="The DOI Logo" width="680" height="53" border="0" align="middle">
    <h3 align="center">Error - DOI Naming Authority [http:] Not Found</h3>
    </td>
    </tr>
     
    <tr>
    <td align="left" valign="top">     </td>
     
    <td align="left" valign="top">
    <hr noshade width="80%" size="1">
     
    <p>The DOI you requested -- </p>
    <p><b>http://dx.doi.org/10.1080/13504639851663</b></p> <p> -- cannot be found in the Handle System.</p>
    <p>Possible reasons for the error are:</p>
    <ul>
    <li>the DOI has not been created </li>
    <li>the DOI is cited incorrectly in your source</li>
    <li>the DOI does not resolve due to a system problem</li>
    </ul>
     
     
     
     
     
    </td>
    </tr>
     
    <tr>
    <td align="left" valign="top">    </td>
    <td><hr noshade width="80%" size="1">
    <p>If you believe you have requested a DOI that should be found, you may report this error by filling out the form below:</p>
    <form action="http://notfound.doi.org/DoiError/servlet" method="POST" enctype="application/x-www-form-urlencoded" name="notFoundForm">
     
    <table width="100%" border="0" cellspacing="2" cellpadding="2">
    <tr>
    <td>
    <table width="100%" border="0" align="center" cellpadding="2" cellspacing="2">
    <tr>
    <th width="35%" align="right" scope="row"><label>Missing DOI:</label></th>
    <td width="65%"><input name="missingHandle" type="text" value="http://dx.doi.org/10.1080/13504639851663" size="35" readonly="true"></td>
    </tr>
    <tr>
    <th align="right" scope="row"><label>Referring Page:</label></th>
    <td><input name="referringPage" type="text" value="" size="35" readonly="true"></td>
    </tr>
    <tr>
    <th align="right" scope="row">E-mail address:</th>
    <td><input name="userEmailAddress" type="text" value="Please enter your email address" size="35"></td>
    </tr>
    <tr>
    <th align="right" scope="row">Comments:</th>
    <td><textarea name="comments" cols="25" rows="3"></textarea></td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td align="center"><p><input name="send" type="submit" value="Submit"></p></td>
    </tr>
    </table>
     
    </form>
     
    </td>
    </tr>
    <tr><td align="left" valign="top">
        </td> <td>
    <hr noshade width="80%" size="1"> <p align="center"> </td>
    </tr>
    </table>
     
    <p><strong><em><small><a href="http://www.doi.org/">DOI Web Site</a><br></small></em></strong></p>
     
    </body></html>
  5. Here is the content of the script (as found in the Run NSAppleScript block in the workflow).  You can adjust the duration of any of the delay commands.  But some delay is likely to be necessary for UI scripting to work successfully.  

     

    on alfred_script(q)

    tell application "Safari" to activate
    delay 2
    tell application "System Events" to tell process "Safari"
    keystroke "," using command down
    delay 2
    tell window 1
    click button "Extensions" of tool bar 1
    delay 1
    click checkbox 1 of group 2 of UI element 1 of scroll area 1 of group 1 of group 1
    end tell
    keystroke "w" using command down
    end tell
    end alfred_script
  6. This is a real time-saver, thanks again.

     

    Would it be possible to add an option to harness BibDesk to produce a formatted citation on the clipboard? (through a modifier key or separate command).

     

    This should just involve adding a few lines to the applescript that calls BD

     

     

    set thePub to selection of document 1

     

    export document 1 using template "template name" to clipboard for thePub

  7. Here is a script: http://bensapplescripts.blogspot.com/2012/05/generate-genius-playlist.html but it seems to be written for iTunes 10 - it doesn't work for me.   Same with this one: http://apple.stackexchange.com/questions/56522/launch-genius-via-applescript?rq=1

     

    The main obstacle is that Genius functionality isn't directly scriptable in Applescript, so it needs to be done with UI scripting, which breaks easily, depends upon the iTunes view, etc.  I have never seen a UI script that uses the new (>) buttons next to tracks, which may not even be Applescriptable, and which are the only way I see to get to Genius functionality in iTunes 11.

     

    Once you have a working script, hooking it into Alfred is easy.

  8. Updated March 26, 2022 to use Python 3 for MacOS 12.3 

     

    Now featuring Universal Action triggers and hotkeys for the following five actions:

     

    Uppercase

    Lowercase

    Capitalize - capitalizes all words (e.g. Posting A New Topic In Share Your Workflows)

    Title Case - capitalizes word except for "the", "in", "of" etc. according to American English title conventions (e.g. Posting a New Topic in Share Your Workflows)

    Sentence Case - capitalizes only the first letter of the first word & converts the rest to lower case

     

    All of these are set to Copy to Clipboard and Paste by default.

     

    There's also a script filter cc which lets you view the query converted and select your choice (like the Code Case workflow).

     

    You can also connect a hot key directly to the cc script filter directly to view the output options without typing the cc command and pasting your text.

     

    ccdemo.thumb.png.613a61bc39aced79368717b23792f127.png

     

    Download:

     

    https://www.dropbox.com/s/8fydkkef1t699et/Case Converter 3.alfredworkflow?dl=0

     

    NB This is a new link and will download as a new workflow - you'll need to migrate any hotkeys and delete or disable the older version.

     

    Here's the old Python 2 version in case anyone wants it:

     

    https://www.dropbox.com/s/3k2lh21g5wnqrkp/Case Converter 2.alfredworkflow?dl=0

     

    The original version is described below and still available, if anyone prefers it.

     

    Workflow Version:

     

    This workflow converts the case of the text on the clipboard.

     

    http://dfay.fastmail.fm/alfred/Case%20Converter.alfredworkflow

     

    There are two workflows which display the following five options:

     

    Uppercase

    Lowercase

    Capitalize - capitalizes all words (e.g. Posting A New Topic In Share Your Workflows)

    Title Case - capitalizes word except for "the", "in", "of" etc. according to American English title conventions (e.g. Posting a New Topic in Share Your Workflows)

    Sentence Case - capitalizes only the first letter of the first word & converts the rest to lower case

     

    The keyword case will transform the text on the clipboard without pasting the result.

    The keyword casep will transform the text on the clipboard and paste (using Applescript System Events)

     

    Hotkey Version:

     

    Here is a version for use with hotkeys which will operate on the active selection in OS X and paste it with the converted text.  These all have a half second delay prior to pasting, which is necessary for Applescript to be able to paste.

     

    http://dfay.fastmail.fm/alfred/Case%20Hotkeys.alfredworkflow

     

    Notes and Revision History:

     

    These use the Title Case perl script found at https://raw.github.com/ap/titlecase/master/titlecase .

     

    If you manage academic citations with BibDesk, Zotero, Papers, Mendeley, etc., Title Case conversion is especially useful for cleaning up downloaded citations.

     

    Updated May 3, 2013 with nicer colored icon thanks to mjv ( http://www.alfredforum.com/user/4384-mjv/ )

     

    Updated February 5, 2014 to handle Sentence Case and to add a second keyword to paste after conversion.

     

    Updated May 20, 2014 with hotkeys

  9. "Way better to add bookmarks like this than with a bookmarklet"

     

    I'm not so sure....I installed this and used it for a couple of days (just dropped into the forum to see the update), but I keep going back to the Delibar bookmarklet (I had shelled out the $9.99 for Delibar years ago and it has been well worth it).  It's not just that old habits die hard - it's just that the bookmarklet has features - already works in any browser, sets selected text as description (or set manually in the Delibar dialog), and tag auto-completion, that are just being added or not available with the Alfred workflow.  

     

    Tag auto-completion is the main appeal of Delibar & it seems that there are obstacles to doing this easily in the Alfred interface - 1) you'd need to generate a new list of tags (slow) or cache a full list of the user's tags - which isn't impossible & 2) the only obvious way to do the auto-complete would be a script filter -- then do you chain multiple scripts together? Or present an option in Alfred for every possibility for each tag, repeating for multiple tags?.  I'd love to see it in the workflow, & I like the elegance of Alfred for most tasks, but without tag completion I don't see it replacing Delibar's bookmarklet.

×
×
  • Create New...