September 18, 201015 yr I have built a proof of concept for a script that scans a folder for files using scriptmaster ListAllFilesRecursivly, sort files based upon filename using (MoveOrRename), and create a record in a Documents table including a reference in a container. Here is the issue. The Script runs fine processing about 1500 files in about 3 or 5 minutes. But upon completion Filemaker is nearly locked up. It hangs even when trying to get to a drop menu like "Format". I have the script flush the cache periodically through the loop. I am kinda at a loss since the script runs at a decent speed yet makes me have to quit and relaunch the application upon completion. Any ideas?
September 19, 201015 yr Author So I did some various optimization and was able to get the script to complete in 58 seconds for 1511 documents.... But Filemaker still locks up upon completion... Judging by top filemaker's Memory use starts increasing exponentially.
September 20, 201015 yr Are you running the module as GUI function? In ScriptMaster 3 all modules were GUI functions, in ScriptMaster 4 we've added a way to specify that a module is a GUI one. Please make sure that you're using the latest ScriptMaster plugin and file.
September 20, 201015 yr Author None of the Modules are running as GUI. As far as I know. I have the register groovy command running in my open script. One Set Variable Command to One RegisterGroovy. I am running SM 4.02. RegisterGroovy( "ListAllFilesRecursively( path )" ; "def result = new StringBuffer();¶ def dir = new File(path);¶ count = 0;¶ listFiles( dir, result );¶ result.toString().trim();¶ ¶ void listFiles( File directory, StringBuffer buff ) {¶ for (eachFile in directory.listFiles() ) {¶ if (eachFile.getName().startsWith(".")) continue;¶ buff.append("n" + eachFile.getPath());¶ if( eachFile.isDirectory() ) {¶ buff.append( File.separator );¶ listFiles( eachFile, buff );¶ }¶ count++;¶ }¶ }" ) RegisterGroovy( "CheckWhetherFileExists( pathToFile )" ; "new File( pathToFile ).exists()" ) RegisterGroovy( "CreateFolder( pathToCreate )" ; "//Really simple version:¶ //return new File(path).mkdirs();¶ ¶ //Version with decent error reporting:¶ File dir = new File(pathToCreate);¶ if( dir.exists() ) return false;¶ if( dir.mkdirs() ) { //Success!¶ return true;¶ } else { //Figure out why it failed¶ File realParent = dir;¶ while( realParent != null && ! realParent.exists() ) {¶ realParent = realParent.getParentFile();¶ }¶ if( realParent != null && !realParent.canWrite() ) {¶ throw new FileNotFoundException("Directory " + dir.getAbsolutePath() + " could not be created because the parent directory " + realParent.getAbsolutePath() + " is not writeable" );¶ } else {¶ throw new FileNotFoundException("Directory + " + dir.getAbsolutePath() + " could not be created because of an unknown error." );¶ }¶ }" ) RegisterGroovy( "GetFileModificationDate( filePath )" ; "return new Date(new File(filePath).lastModified());" ) RegisterGroovy( "MoveOrRenameFile( originalPath ; moveToPath )" ; "File moveToFile = new File( moveToPath );¶ boolean success = new File( originalPath ).renameTo( moveToFile );¶ return success;" ) RegisterGroovy( "DeleteFileOrFolder( pathToDelete )" ; "if( pathToDelete == null ) throw new Exception("You must provide a pathToDelete");¶ File toDelete = new File(pathToDelete);¶ if( ! toDelete.exists() ) {¶ return false;¶ } else {¶ deleteRecursive( toDelete );¶ }¶ ¶ void deleteRecursive( File fileToDelete ) throws IOException {¶ if( fileToDelete.isDirectory() ) {¶ File[] children = fileToDelete.listFiles();¶ for( int n=0; n deleteRecursive( children[n] )¶ }¶ }¶ if( ! fileToDelete.delete() ) {¶ throw new IOException("Could not delete " + fileToDelete.getAbsolutePath());¶ }¶ }" ) RegisterGroovy( "GetFileExtension( html )" ; "import java.util.regex.*;¶ ¶ String regex = "(?<=.)(.*)";¶ ¶ Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);¶ Matcher matcher = pattern.matcher(html);¶ ¶ List result = new LinkedList();¶ while (matcher.find()) {¶ result.add( matcher.group(1) );¶ }¶ return result;" )
September 20, 201015 yr It looks like all of the functions you have there are running as GUI functions. You will need to add "isGui=false" as a parameter on your function to have it run as a non-gui function. RegisterGroovy( functionSignature; yourGroovyCode; "isGui=false")
September 20, 201015 yr Author Alright, So I added the isGui = False, ran the script again. Same issue. I have attached a sample code to check to see if my syntax is wrong. RegisterGroovy( "CheckWhetherFileExists( pathToFile )" ; "new File( pathToFile ).exists()"; "isGui = false" )
September 21, 201015 yr I have exactly the same issue with this function. The situation is as follows: a list of paths, and a FM script looping over the path, and check each time if the file exists. Runs very well, but at the end it freezes FileMaker.
September 21, 201015 yr Could you post an example FM file to show this happening which I could look at?
September 21, 201015 yr Author Attached. For filename the script is expecting name 3lettersofmonth2010 Inv.fileextension so burningpony aug2010 Inv.pdf It is expecting a hard coded filepath to look for files FYI. filetest.fp7.zip
September 21, 201015 yr Here is another example. There are 15000 records in the file, but also when I only have 2000 records in my foundset it causes this crash. I don't see anything special in the error log. What is the difference between a GUI function and another one? Or what is the difference in behavior? TestSM.zip
September 22, 201015 yr I wasn't sure what to run in your first example, or which scripts I would need to adjust, so I took a look at the second example you uploaded. When I first ran it I noticed that you were missing "isGui=false" in your RegisterGroovy call. I experienced the same freezing as you with this parameter missing. Once I added "isGui=false", quit filemaker, re-opened the file and re-registered the function I did not experience the freezing any more. Can you try adding "isGui=false" to your RegisterGroovy function as well, quit filemaker and re-open your file (the quit is needed to clear the function registration) and see if it still happens for you?
September 22, 201015 yr Author I reworked my example to be a easier to demonstrate. This will simply scan your desktop for the first 2000 files. The Script to run is Scan Desktop. All functions have isGui=false filetest2.fp7_2.zip
September 22, 201015 yr I wasn't sure what to run in your first example, or which scripts I would need to adjust, so I took a look at the second example you uploaded. When I first ran it I noticed that you were missing "isGui=false" in your RegisterGroovy call. I experienced the same freezing as you with this parameter missing. Once I added "isGui=false", quit filemaker, re-opened the file and re-registered the function I did not experience the freezing any more. Can you try adding "isGui=false" to your RegisterGroovy function as well, quit filemaker and re-open your file (the quit is needed to clear the function registration) and see if it still happens for you? This solved the issue for me. But why does this matter? What is the reason we need to add this? As I understood scriptmaster has some issues with GUI functions? Thanks!
September 22, 201015 yr Java handles the two types of functions differently, and running it as a non-gui function requires much fewer resources and allows it to run much faster, so FileMaker and Java don't have to worry about creating invisible windows, removing them, maintaining focus, and a host of other things that happen when you use a GUI function.
September 25, 201015 yr Author Even with isGui=false I am still getting a crash with filetest2. Any Advice?
September 27, 201015 yr Double check and make sure that the flag is in your registration fucntions. Filetest2.fp7 does not have the isGui=false parameter in the RegisterGroovy function calls, so you will need to go back and type that in manually into each RegisterGroovy function call.
September 27, 201015 yr Author Every RegisterGroovy Function in the Open script of FileTest2.fp7 has the "isGui = False" flag as its last parameter sent is this incorrect? I already had to manually enter them prior to uploading that file to the forum. Below is the code for the first RegisterGroovy Command RegisterGroovy( "ListAllFilesRecursively( path )" ; "def result = new StringBuffer();¶ def dir = new File(path);¶ count = 0;¶ listFiles( dir, result );¶ result.toString().trim();¶ ¶ void listFiles( File directory, StringBuffer buff ) {¶ for (eachFile in directory.listFiles() ) {¶ if (eachFile.getName().startsWith(".")) continue;¶ buff.append("n" + eachFile.getPath());¶ if( eachFile.isDirectory() ) {¶ buff.append( File.separator );¶ listFiles( eachFile, buff );¶ }¶ count++;¶ }¶ }"; "isGui = false" ) Edited September 27, 201015 yr by Guest
September 27, 201015 yr Author Apparently "isGui = false" cannot have any spaces. "isGui=false" ran without ending in a crash. Edited September 27, 201015 yr by Guest
Create an account or sign in to comment