Last active
April 17, 2016 20:51
-
-
Save temmings/10c27b1d8b63e3982523b1ec7f8a3e8f to your computer and use it in GitHub Desktop.
OmniFocus 2: Import action per line, for Automator / 選択範囲を1行毎にアクションとして取り込む
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* Import action from selected at per line, to temporary project. *) | |
on run {input, parameters} | |
set theRawLines to my getRawLines(input as string) | |
if not length of theRawLines is greater than 0 then return input | |
set theTrimmedLines to my getTrimmedLines(theRawLines) | |
if not length of theTrimmedLines is greater than 0 then return input | |
tell application "OmniFocus" | |
tell default document | |
set now to current date | |
set projectName to "bulk action at " & (now as string) | |
set theProject to make new project with properties {name:projectName} | |
repeat with actionName in theTrimmedLines | |
tell theProject to make new task with properties {name:actionName} | |
end repeat | |
end tell | |
end tell | |
return input | |
end run | |
on getRawLines(input) | |
set theRawLines to my split(input, {return, linefeed}) | |
return theRawLines | |
end getRawLines | |
on getTrimmedLines(theLines) | |
set theTrimmedLines to {} | |
repeat with theLine in theLines | |
if length of theLine is greater than 0 then | |
set theTrimmedLine to my trim(true, theLine) | |
-- suppress empty line | |
if length of theTrimmedLine is greater than 0 then | |
set theTrimmedLines to theTrimmedLines & theTrimmedLine | |
end if | |
end if | |
end repeat | |
return theTrimmedLines | |
end getTrimmedLines | |
on isValidName(value) | |
return | |
end isValidName | |
on split(input, delimiters) | |
set AppleScript's text item delimiters to delimiters | |
set output to input's text items | |
set AppleScript's text item delimiters to {""} | |
return output | |
end split | |
-- http://macscripter.net/viewtopic.php?id=18519 | |
on trim(theseCharacters, someText) | |
-- Lazy default (AppleScript doesn't support default values) | |
if theseCharacters is true then set theseCharacters to ¬ | |
{" ", tab, linefeed, return, ASCII character 0} | |
if length of someText is 0 then return "" | |
repeat until first character of someText is not in theseCharacters | |
if length of someText is 1 then return "" | |
set someText to text 2 thru -1 of someText | |
end repeat | |
repeat until last character of someText is not in theseCharacters | |
if length of someText is 1 then return "" | |
set someText to text 1 thru -2 of someText | |
end repeat | |
return someText | |
end trim |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment