Folder action script not working

I have the following script as folder action.  However, it stopped working after an upgrade of the OS.  Can anyone see what is wrong?

 

It is a disk image that is being loaded and once loaded it should open a FMP file that I like to be opened once the disk image is loaded.

 

on adding folder items to this_folder after receiving added_items

       tell application "Finder"

              repeat with tItem in added_items

                      set tName to the name of tItem --get the name of each added_items                

                      if tName = "DiskimageName" and class of (item tItem) is disk then

                             tell application "VeraCrypt"

                                    quit

                                    delay 1

                             end tell

                             activate

                             open document file "FilemakerDatabase.fmp12" of tItem

                             exit repeat

                      end if

              end repeat

       end tell

end adding folder items to

 

I have selected Volumes and Desktop and my OS disk (see pic) to run the script but that does not make a difference. 

 

Any idea?

 

 

Posted on Sep 10, 2020 12:13 AM

Reply
11 replies

Sep 30, 2020 11:35 AM in response to ChangeAgent

Based on the same script above? Or did you make changes?


The original script doesn't open any windows (except for the Filemaker document if it's found), so it's hard to see how you could be getting any windows open. What windows are these? Filemaker windows? Finder windows? what do they show? the disk? some random location?


More details please.

Sep 30, 2020 11:37 AM in response to heyll44

heyll44 wrote:

I'm faicng the same issue in my script. I'm trying to add the drive location to get the exactly address.

Not entirely sure that's related to the OP. May be better to start a new thread. At the very least show your code. It's hard enough to troubleshoot AppleScript without being blindfolded, put in an unlit, windowless room and told to fix the problem with our hands tied behind our backs.


Sep 23, 2020 11:52 AM in response to ChangeAgent

Folder Actions are notoriously hard to debug since they are inherently background actions. It would help if you described the failure state.


For example, there are three functional component to your script:


1) Identify the mounted disk

2) Quit VeraCrypt

3) Open the Filemaker database


Knowing at which stage it fails would help. For example:


a) does it fail to identify the disk (name misspelled? are disk images identified as 'disk'? (I honestly don't know off hand).

b) does the VeraCrypt app quit?

c) Does the Filemaker database open?


I'm guessing not c) because then there wouldn't be an issue, so you need to move back up the stack to find out where it fails. Start by checking the lines one by one - for example, can you run the 'open' command independently?


Ultimately there's nothing obviously wrong with your script, so some sleuthing is required.


You can copy the code minus the 'on adding folder items to...' line, and change added_items to (choose file) to run the script in Script Editor if that helps.

Sep 24, 2020 8:45 AM in response to Camelot

will give it a go, thanks for your tips.



Camelot wrote:

Knowing at which stage it fails would help. For example:

a) does it fail to identify the disk (name misspelled? are disk images identified as 'disk'? (I honestly don't know off hand).
b) does the VeraCrypt app quit?
c) Does the Filemaker database open?

I think it hangs at a) as nothing happens when it mounts.

Sep 24, 2020 10:24 AM in response to ChangeAgent

Here is my common front end script. The idea is to take what ever input you get and quickly move to common code. This allows to to debug the common code in the script debugger.


(* 
  Demonstration of how dropping files on AppleScript icon works.  Shows how to debug via on run path. Shows items added to folder.
  
 Save as an Application Bundle.  Don't check anything.
 
 Shows log statement.
 
 It is easier to diagnose problems with debug information. I suggest adding log statements to your script to see what is going on.  Here is an example.
	
For testing, run in the Script Editor.
	1) Click on the Event Log tab to see the output from the log statement
	2) Click on Run


Author: rccharles

 *)


-- Gets invoked here when you run in AppleScript editor.

on run
	--  debug lines
	set desktopPath to (path to desktop) as string
	
	-- here is a log statment.
	log "desktopPath = " & desktopPath
	
	-- Be sure to select a file on your DESKTOP.
	set see to alias (desktopPath & "Picture 1.png")
	
	-- Simulate dropped items list.
	set dropped_items to {see}
	
	common(dropped_items)
	
end run


-- Folder actions.
-- Gets invoked here when something is dropped on the folder that this script is monitoring.
-- Right click on the folder to be monitored. services > Folder Action Settup...

on adding folder items to this_folder after receiving added_items
	
	common(added_items)
	
end adding folder items to



-- Gets invoked here when something is dropped on this AppleScript icon

on open dropped_items
	
	common(dropped_items)
	
end open



on common(dropped_items)
	
	-- Write a message into the event log.
	log "  --- Starting on " & ((current date) as string) & " --- "
	tell application "Script Editor"
		activate
	end tell
	
	
	log "class = " & class of dropped_items
	
	
	repeat with droppedItem in dropped_items
		log "The droppedItem is " & droppedItem & "; class = " & class of droppedItem
		
		display dialog "The droppedItem is " & droppedItem giving up after 3
	end repeat
	
	
end common






To debug the invisible stuff, write somethings to a log.


logging to a file example ----------->


Robert

PS Why the two ways of posting code? Ran into the 5k limit with two code posts. Posts as a file doesn't run into this limit. fyi: I've complained about this before.









Oct 2, 2020 3:49 AM in response to ChangeAgent

Good morning all thanks for answering. I was on the road hence the delay.


as i culd not get the original to work properly I swictche to making it a Automator action.




I kept the script simple to do only one action. if that works I add the next step of quitting etc.


Here is the script.


on run {input, parameters}
	
	-- define the volume name and the application to start
	set triggeringVolumeName to "Hanuman2"
	
	-- walk through all newly mounted volumes
	repeat with aMountedVolumeAlias in input
		
		-- get the volume name from the given alias
		tell application "System Events" to set mountedVolumeName to name of aMountedVolumeAlias
		
		-- compare the volume name with the defined trigger name
		if mountedVolumeName is triggeringVolumeName then
			
			-- launch the target file
			tell application "Finder"
				delay 1
				activate
				select file "Hanuman.fmp12" of disk "Hanuman2"
				open selection
			end tell
			
			-- all is done stop checking
			exit repeat
			
		end if
		
	end repeat
	
	return input
end run



This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Folder action script not working

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.