The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniPlan > OmniPlan Extras
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
Sample of AppleScript to add to or modify custom data Thread Tools Search this Thread Display Modes
Figured this out and thought it might be useful to someone. The situation is that I want to add or modify custom data for a task or tasks. However, there is already custom data associated with those tasks. So, let's say a task already has a custom data field called "Custom1" set to "Yes". I want to add a new custom data field, "Custom2" set to "No".

The following

Code:
set newCustomData to {custom2:"No"}

tell application "OmniPlan"
	tell front document
			repeat with eachTask in every task
				set custom data of eachTask to newCustomData
			end repeat
	end tell
end tell
would NOT be good because it would replace all of the custom data for each task with newCustomData, effectively wiping out the existing custom data, meaning the value of Custom1 would now be blank. That's not what we want. Better is this:

Code:
set newCustomData to {custom2:"No"}

tell application "OmniPlan"
	tell front document
			repeat with eachTask in every task
				set oldData to custom data of eachTask  --New stuff
				set newData to newCustomData & oldData  --New stuff
				set custom data of eachTask to newData --New stuff
			end repeat
	end tell
end tell
This code concatenates a record containing the new custom data onto the front of a record containing the current custom data and then writes the combined record to the task, thus preserving all existing custom data.

If you want to modify existing custom data, you can take advantage of the fact that the value of the leftmost record is preferred when the same key exists in both records. That is, {custom2:"No"} & {custom2:"Maybe", custom1:"Yes"} yields {custom2:"No",custom2:"Yes"}. So, the code just above would also serve to update existing an existing custom data field "custom2" to "No", leaving other existing custom data in place.
 
I tried this, but it only works for some (out of the 50) tasks that are created in one run?! Also, the data does not show up in the inspector.
Do you confirm that, or is it just here?

Thanks!
Stefan
 
Hmmm. It has always worked for me, although it is very slow to show up in the main display. There seems to be a lag in how often that updates (I've had luck toggling display of the changed custom data field on and off). It has, however, always shown up in the inspector more or less immediately.

I'll see if I can duplicate non-performance. Any leads on when it does and does not work?
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes



All times are GMT -8. The time now is 11:29 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.