May 9, 201114 yr Hi, I need help... I have this applescript in a calculated field in filemaker: "tell application \"Finder\"¶" & " delete file \"Snow Leopard:Users:ton:Desktop:blabla:blaimport.txt" &"\" ¶ end tell" What is the syntax to replace this file path with a fieldvalue or filemaker variabele???
May 9, 201114 yr Depends on the context, but in a script for example: Set Variable( $path ; "Snow Leopard:Users:ton:Desktop:blabla:blaimport.txt" ) Set Variable( $x ; "tell application \"Finder\"¶ delete file " & "\"" & $path & "\"¶ end tell" ) Perform AppleScript ( $x )
May 10, 201114 yr Author Depends on the context, but in a script for example: Set Variable( $path ; "Snow Leopard:Users:ton:Desktop:blabla:blaimport.txt" ) Set Variable( $x ; "tell application \"Finder\"¶ delete file " & "\"" & $path & "\"¶ end tell" ) Perform AppleScript ( $x ) Thank you for your fast reaction! All I want is to delete a file in the same folder as the application. The path is in a calculated field in FM (path with colon's replaced for slashes), I want to use that value in a script to delete the file. The path has to be calculated because it is not always the same. When I paste your example in a calculated FM field I cannot save the field because of errors. I also have this script: set x to POSIX file ((POSIX path of (path to me)) & "/..") as text set x to x & "blaimport.csv" tell application "Finder" delete the x end tell This worked for me but only as a standalone applescript and not from FM.
May 10, 201114 yr It might help to know what version of FileMaker you're running. It's a good idea to set that in your profile. If you really want to use the FileMaker folder, you can use the Get(FileMakerPath) function. Other functions you may be interested in: Get(FilePath) Get(DesktopPath) Get(DocumentsPath) Get(TemporaryPath) I'm not sure why you want to use a calculated field for this, since it's going to be scripted anyway, but you could for example have this in your field: "tell application \"Finder\"¶ delete file "\<<xyz>>"\¶ end tell" Your script could then be: Set Variable( $path ; Get(FileMakerPath) & "blaimport.txt" // or whatever you're using to get the file path ) Set Variable( $x ; Substitute( yourApplescriptCalcField ; "<<xyz>>" ; $path ) ) Perform AppleScript ( $x )
May 12, 201114 yr Author I still cannot get it to work... I think i getting confused by Applescript and Filemakerscript. I simply want (from Filemaker pro advanced 11) to delete a file on the desktop (changed my first plan) because the path to the desktop is not always the same filemaker has to deliver the path. The following in a in a filemakerfiled, (your example): "tell application \"Finder\"¶ delete file "\<<xyz>>"\¶ end tell" How do I get the path and filename in <<xyz>> ??? BTW, when I paste your example script "set Variable and so on I cannot save that script (applescript refuse to save because of a error)
May 12, 201114 yr If you have a field named "Filename" in a table named "YourTable", you can simply call the Perform AppleScript[] script step, with the following calculated AppleScript = "tell application \"Finder\"¶ delete file " & Quote ( YourTable::Filename ) & " of (path to desktop)¶ end tell"
May 12, 201114 yr delete file "\<<xyz>>"\¶ That was a typo, should be: delete file \"<<xyz>>\"¶ (with the backslashes before the quotes) How do I get the path and filename in <<xyz>> ??? Did you look at the two scripts I posted? The Set Variable steps? Look, if you really want the whole script to show up in a calculated field, try this: "tell application \"Finder\"¶ delete file \"" & Let( [ path = Get ( DesktopPath ) ; /* or use Get ( FileMakerPath ) or whatever you need here*/ pathTrim = Replace ( path ; 1 ; 1 ; "" ) ; /* gets rid of the leading slash */ pathMac = Substitute ( pathTrim ; "/" ; ":" ) ; /* applescript-friendly path */ result = pathMac & yourTable::yourFileName ] ; result ) & "\"¶end tell" The calc uses a field called yourFileName in a table called yourTable. I tested this and it works. (I was on a PC for the previous posts and could not test, sorry for any errors.)
May 12, 201114 yr Author If you have a field named "Filename" in a table named "YourTable", you can simply call the Perform AppleScript[] script step, with the following calculated AppleScript = "tell application \"Finder\"¶ delete file " & Quote ( YourTable::Filename ) & " of (path to desktop)¶ end tell" This simple solution works for me.... Thanks again. Now only have to find the same trick for delete a file from Windows, is this a topic for this forum? Is
May 12, 201114 yr Author That was a typo, should be: delete file \"<<xyz>>\"¶ (with the backslashes before the quotes) Did you look at the two scripts I posted? The Set Variable steps? Look, if you really want the whole script to show up in a calculated field, try this: "tell application \"Finder\"¶ delete file \"" & Let( [ path = Get ( DesktopPath ) ; /* or use Get ( FileMakerPath ) or whatever you need here*/ pathTrim = Replace ( path ; 1 ; 1 ; "" ) ; /* gets rid of the leading slash */ pathMac = Substitute ( pathTrim ; "/" ; ":" ) ; /* applescript-friendly path */ result = pathMac & yourTable::yourFileName ] ; result ) & "\"¶end tell" The calc uses a field called yourFileName in a table called yourTable. I tested this and it works. (I was on a PC for the previous posts and could not test, sorry for any errors.) I used the above example: "tell application \"Finder\"¶ delete file " & Quote ( YourTable::Filename ) & " of (path to desktop)¶ end tell" This works for me, is your example better??? The way to get the pathname is a lot different your way, is there a reason for???
May 13, 201114 yr If your file is always on the desktop then Applescript gives you an easy way to do that. If you want to use other paths, you may need a different method. I'm glad you found a solution that works for you.
Create an account or sign in to comment