Integrating Folder Actions

Hello All,
I am working on the next version of WorkfloPro and have hit a wall. I am trying to pass data between scripts and it is kicking my butt. The problem seems to be getting data from workflopro.scpt to my folder actions script and back. The problem seems to be due to workflopro.scpt being part of an app bundle. I have tried the simple way:

–This is my scpt that is called by System Events when Folder Actions is enabled–


on adding folder items to thisFolder after receiving addedItems
tell application "WorkfloPro 1.0"
get workflowFolder
end tell

tell application "Finder"
copy addedItems to folder workflowFolder
end tell


I am just trying to pass the added items to a folder that is already selected via the GUI.
this does not work. i assume it is because workflowFolder is not assoiciated with any class. i can get any data that has been defined as an object in the interface, but not just plain old variables. I have tried MANY different ways to get this data, but no luck. Anyone got ideas? By the way folder actions IS working. I just can’t get my scripts to share nicely.
thanks,

This isn’t exactly an answer to your question, but if it were me, I’d avoid folder actions all together and add an ‘on idle’ handler to your AStudio app in which you put monitoring routines for the chosen folder. You could set up user preferences to allow the selection of what folder(s) to monitor for changes… This is generally more reliable and easier to use than folder actions.

Thanks TJ,
I actually started working with an on idle handler a few days ago. I’ll let you know if I get it working. Any word on if Apple is going to make it easier to share data between scripts??

I haven’t heard any information in regards to this specifically, but it wouldn’t surprise me to find out that and a whole lot more is coming with AppleScript 2.0.
Which, by some accounts might be 10.3 (aka Panther) and by others not until after that.

Well, got the on idle handler to work. A little sloppy I think, but it works. This will work if you are watching a folder for added files. I am using comment to track the status of the file, plus it works well for my application. This will be out of context; most of the input happens elsewhere in the script/GUI:


on idle theObject
	tell window "main"
		--check to see if watching is enabled
		if stateOfwatchSwitch is equal to 1 then
			---Get copyright info for comments
			set copyright to contents of text field "copyrightField" of tab view item "importTab" of tab view "tabView"		
			
			tell application "Finder"
				--Check to see if anything has been updated				
				if (count every file in folder importFolder) > (count every file in folder workflowFolder) then
					--If an added item is present then copy to workflowFolder and set comment
					set listImportFolder to list folder importFolder without invisibles
					set numItems to number of items in listImportFolder
					repeat with i from 1 to numItems
						--Initially set to read kind of alias
						set importItem to ((importFolder as string) & item i of listImportFolder)
						--Make sure it is not a folder
						set kindOfItem to kind of alias importItem
						if kindOfItem ? "Folder" then
							--set to file to get/set comment
							set importItem to file importItem
							--Using comment to determine status of file
							if comment of importItem is not equal to copyright then
								duplicate importItem to workflowFolder with replacing
							end if
							--set comment of importItem so sub knows it has been copied
							set comment of importItem to copyright
						end if
					end repeat
					
					--Do the same thing for workflowFolder and batch as required
					set listWorkflowFolder to list folder workflowFolder without invisibles
					--process any file that has not had it's comment set in the workflowFolder--one at a time
					set numItems to number of items in listWorkflowFolder
					repeat with i from 1 to numItems
						set workflowItem to ((workflowFolder as string) & item i of listWorkflowFolder)
						--Make sure it is not a folder
						set kindOfItem to kind of alias workflowItem
						if kindOfItem ? "Folder" then
							set workflowItem to file workflowItem
							if comment of workflowItem is not equal to copyright then
								--batch workflowitem
							end if
							set comment of workflowItem to copyright
						end if
					end repeat
				end if
			end tell
		end if
	end tell
	
	--run idle handler every 5 seconds
	return 5
end idle