Help, please. I am trying to write a very simple(?) applescript that would calculate the remaining funds available on a task (total task cost - total budget (custom data field), and all I get is complaints about data type mismatches. Can anyone please help? Even if you could give me an example to modify, it would be very much appreciated. Thanks, Keith Lohmann
It’s easier to help if you post your script. :)
Here is the script - it is complaining about the Total Task Cost (regular, not custom) field.
Sorry - here is the script
tell application “OmniPlan”
repeat with t in tasks of front document
if task type of t is group task then
set total to value of custom data entry “Current_Allocation” of t as real
set spent to value of TotalTaskCost of t as real
set remaining to value of custom data entry “Remaining_Balance” of t as real
set value of remaining to (total of t) - (spent of t)
set value of custom data entry “Remaining_Balance” of t to remaining of t as real
I’m not sure what the
as real was for, but it doesn’t seem necessary.
I also took out a few
of t phrases, where you’re referring to a local variable, not a property of an OmniPlan task.
TotalTaskCost is not defined, so I assumed you meant
tell application "OmniPlan" repeat with t in tasks of front document if task type of t is group task then set total to value of custom data entry "Current_Allocation" of t set spent to total cost of t set remaining to total - spent set value of custom data entry "Remaining_Balance" of t to remaining end if end repeat end tell
Oh, and if you have a currency symbol or something in Current_Allocation, you’ll want to remove that from the OmniPlan file, or you’ll need to add clever string parsing code here.
Thanks for the assistance. I tried the code, and I’m getting the error “error “OmniPlan got an error: Can’t make TotalTaskCost of item 1 of every task of document 1 into type specifier.” number -1700 from TotalTaskCost of item 1 of every task of document 1 to specifier”.
The field that I am trying to use here is the “predefined” field “Total Task Cost” in omniplan. Can’t seem to get it to work.
Thanks for the reply lizard. I think what has me stuck is how to I represent the standard field in omniplan called “Total Task Cost” in applescript so that I can use the value in an applescript calculation? I have no idea of where to look such information up. It seems to be nowhere in the omniplan documentation, and applescript documentation is not specific to omniplan either.
Thanks again for the help! K.
That’s what this line does:
set spent to total cost of t
I use Script Editor (included with OS X), which has a Library (available from the Window menu) where you can view the AppleScript dictionary for specific applications. For example, here’s the details on OmniPlan’s
task object, including properties like
I have omnifocus listed in the library, but not omniplan. How do I add it?
Lizard - Got omniplan added. Now sorting through and figuring out how to write the “Total Task Cost” field.
Glad you got sorted. I do hope you’ll post again next time you get stuck.