AHaghgoo Posted May 29, 2013 Share Posted May 29, 2013 I downloaded the following workflow and have been having trouble using it to indicate the particular TaskPaper file I wish to append tasks to. I have corresponded with the developer, Gianni Rondini, but he couldn't find the reason why the Alfred workflow doesn't properly compute and he suggested I come here to see if someone might know what the issue is between the workflow and Alfred. I've screencasted the issue and uploaded to . The link to the workflow above explains how it works, but in short, the workflow works when creating a new TaskPaper list, but makes Alfred non responsive when trying to append tasks to a particular file with the '#' preceding the filename. And unfortunately there is no log in the Console.app that might explain what is going on. Any consideration on this is greatly appreciated. Here's the code for the workflow and I'm on MacOS 10.8.3 using Alfred v2.0.3 (187): -- 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 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 "find ~ -iname " & 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 Link to comment
dfay Posted May 29, 2013 Share Posted May 29, 2013 I've tested it and have the same issue. But if I wait a few minutes, Alfred becomes responsive again. And once it does there is an error in system.log : May 29 13:37:00 ... Alfred 2[356]: [ERROR] AppleScript Error: { Link to comment
dfay Posted May 29, 2013 Share Posted May 29, 2013 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 Link to comment
dfay Posted May 29, 2013 Share Posted May 29, 2013 (edited) 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? Edited May 29, 2013 by dfay Link to comment
dfay Posted May 29, 2013 Share Posted May 29, 2013 (edited) 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 Edited May 30, 2013 by dfay Link to comment
AHaghgoo Posted May 30, 2013 Author Share Posted May 30, 2013 Thank you for taking your time and considering this dfay, I really appreciate it. And yea, I also have my TaskPaper files inside Dropbox so your specific fine tuning would work for me personally. I've contacted Gianni and linked to this thread so I'm hoping he'll get a chance to see this sometime soon. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now