BonB Posted November 11, 2013 Posted November 11, 2013 I want to be able to restrict user to specific Finder folders for import into Filemaker. I also need to rename and move, from a designated folder, Finder folders, from within Filemaker. So far, this is my feeble attempt in AppleScript. I don't know how to be able to work with folders within folders. Thanks for any help. ------------------------------------------------------------ tell application "FileMaker Pro Advanced" set fName to cell "tbl_Doc::UserFolderMN_DocuSet" of current record end tell property ChooseFolder : "Choose Document Folder" try choose folder with prompt ChooseFolder set TargetFolder to the result as alias set SourceFolder to ("Macintosh_HD:Users:Users:JohnG:Desktop:Upload:") on error return end try try tell application "Finder" if the name of TargetFolder is in SourceFolder then move folder (TargetFolder) to "Macintosh_HD:Users:Shared:ModernExpertFolder:Document_folders" as alias set TargetFile to last file of TargetFolder as alias set the name of folder (TargetFolder) to (fName) as text set the clipboard to "Macintosh_HD" & (POSIX path of (TargetFolder)) tell application "FileMaker Pro Advanced" to set cell "tbl_Doc::NewDocFolderPath" of current record to the clipboard tell application "FileMaker Pro Advanced" to set cell "tbl_Doc::DocPicture" of current record to TargetFile else display dialog "Invalid Folder." buttons {"OK"} default button 1 activate application "FileMaker Pro Advanced" end if end tell end try
Lee Smith Posted November 11, 2013 Posted November 11, 2013 Automatic message This topic has been moved from "Managing Scripts" to "AppleScript & Automator".
Fenton Posted November 13, 2013 Posted November 13, 2013 I'd hate to leave this empty, so I'll give it a chance. I had some trouble with a few things. The first being that I had neither a FileMaker file nor the folders to work with. But the folders I could create. Then a few things in the AppleScript code. One is the "Users:Users:" in one, which just seemed too odd, so I made it just "Users:"; you can do whatever is correct for you. The one thing which I could not get to work was the: if the name of TargetFolder is in SourceFolder then It never said yes, and I didn't know what to change to make it happen (anyone?). So I changed to something else, using a name of what the folder would be, and just a test for it as an alias; which will return an error if it isn't there. I also moved some stuff around a little. I don't like to put a FileMaker routine inside a Finder area. Because it is better to keep FileMaker free if possible; so that you do not have to say "which" FileMaker you're talking about, so it will work for either "FileMaker Pro" or "FileMaker Pro Advanced". You do that by not "telling" FileMaker. It knows who it is; it is the app running the AppleScript, via a script step. You only need to tell FileMaker if you've got it stuck inside some other apps area. I also don't really understand the whole idea here, as it seemed like there were 3 folders involved: one which they chose, one which is on the Desktop, and one in the Shared folder (which ended up with the chosen folder). It is the one on the Desktop which seemed odd; it seems like of like a "value list" kind of thing :-? Anyway, this is my version; hopefully it does something useful. The commented out FileMaker lines will work in FileMaker, they must be made active to work on just AppleScript; this is a common method, so you can run in FileMaker or run in AppleScript (for testing): --tell application "FileMaker Pro Advanced" set fName to cell "tbl_Doc::UserFolderMN_DocuSet" of current record --end tell property ChooseFolder : "Choose Document Folder" property an_error : false try choose folder with prompt ChooseFolder set TargetFolder to the result as alias set SourceFolder to ("Macintosh_HD:Users:JohnG:Desktop:Upload:") on error -- they might have hit cancel return end try tell application "Finder" set folder_test to SourceFolder & (name of TargetFolder) try get folder_test as alias move folder (TargetFolder) to folder (alias "Macintosh_HD:Users:Shared:ModernExpertFolder:Document_folders:") set TargetFile to last file of TargetFolder as alias set the name of folder (TargetFolder) to (fName) as text set NewBocFolderPath to "Macintosh HD" & (POSIX path of (TargetFolder)) on error set an_error to true end try end tell --tell application "FileMaker Pro Advanced" activate if an_error is false then set cell "tbl_Doc::NewDocFolderPath" of current record to NewBocFolderPath set cell "tbl_Doc::DocPicture" of current record to TargetFile save else display dialog "Invalid Folder." buttons {"OK"} default button 1 end if --end tell
comment Posted November 13, 2013 Posted November 13, 2013 (edited) The one thing which I could not get to work was the: if the name of TargetFolder is in SourceFolder then It never said yes, and I didn't know what to change to make it happen (anyone?). I am not entirely sure what is being tested here. If I am guessing correctly, then something like the following should work, I think: tell application "Finder" if name of TargetFolder is in name of every folder of entire contents of SourceFolder then ... else ... end if end tell This returns true if TargetFolder is contained by SourceFolder (at any level of nesting). Well, actually, the test is by name only, so if you selected a similarly-named folder outside the SourceFolder, you will get a false positive. Edited November 13, 2013 by comment
Fenton Posted November 13, 2013 Posted November 13, 2013 Thanks comment (Newbies will also, if he returns :-). That was what I was "almost thinking of, but couldn't remember all the details"; the "every folder of" was the piece I was missing. My version was a good test for an exact folder, in a known place, but did not handle "any level of nesting." He had hard coded the folder it was in, as a fixed folder on the Desktop,* so other folders should not happen. *However, the hard coded Desktop is only going to work for one person. If you logs in a again, I can give him some tricks on using a dynamic user name; also the "Macintosh_HD" vs. "Macintosh HD" (or whatever it is). That can be done in either FileMaker itself (and sent to the AppleScript), or in the AppleScript itself (likely cleaner, unless you want to use it on other things).
BonB Posted November 13, 2013 Author Posted November 13, 2013 Thank you so very much for taking the time to respond, Fenton and Comment. With your posts, I will try to figure this out. So far no luck, but I need more time to grasp this. The way I am trying to do this maybe all wrong, but basically I am attempting to prevent a user from moving any vital system folder to a wrong location. That's why the "hardwired" folder on the Desktop, which will serve as a central upload location from which the user will be able to select a folder, from Filemaker, move it and rename for permanent storage and future access from within Filemaker. This is a project of converting a large Access database to FM and I must keep old external data the way it was, connected to FM through imbedded file paths. I did try a 'list' of folders to exclude from being accessible by the script, and it worked fine. But I thought that designating a special location would be less dangerous. Perhaps there is another way? Thank you for noticing, the extra "Users" was a mistake posting, Macintosh_HD is correct, I renamed it for something else... ----------------------------------------------- Ok, I think this works OK now. Thank you, thank you!!! ------------------------------------------------ tell application "FileMaker Pro Advanced" set fName to cell "tbl_Doc::UserFolderMN_DocuSet" of current record end tell property ChooseFolder : "Choose Document Folder" try choose folder with prompt ChooseFolder set TargetFolder to the result as alias on error return end try set SourceFolder to ("Macintosh_HD:Users:JohnG:Desktop:Upload" ) as alias try tell application "Finder" if name of TargetFolder is in name of every folder of entire contents of SourceFolder then move folder (TargetFolder) to "Macintosh_HD:Users:Shared:ModernExpertFolder:Document_folders" as alias set TargetFile to last file of TargetFolder as alias set the name of folder (TargetFolder) to (fName) as text set the clipboard to "Macintosh_HD" & (POSIX path of (TargetFolder)) tell application "FileMaker Pro Advanced" to set cell "tbl_Doc::NewDocFolderPath" of current record to the clipboard tell application "FileMaker Pro Advanced" to set cell "tbl_Doc::DocPicture" of current record to TargetFile else display dialog "Invalid Folder." buttons {"OK"} default button 1 activate application "FileMaker Pro Advanced" end if end tell end try
BonB Posted November 13, 2013 Author Posted November 13, 2013 I am not entirely sure what is being tested here. If I am guessing correctly, then something like the following should work, I think: tell application "Finder" if name of TargetFolder is in name of every folder of entire contents of SourceFolder then ... else ... end if end tell This returns true if TargetFolder is contained by SourceFolder (at any level of nesting). Well, actually, the test is by name only, so if you selected a similarly-named folder outside the SourceFolder, you will get a false positive. Thank you very, very much, this solved my problem, I think. Is there possibly a way to have only the exact name of TargetFolder tested here, so there would be less confusion?
comment Posted November 13, 2013 Posted November 13, 2013 Is there possibly a way to have only the exact name of TargetFolder tested here Oh, the name is exact. The problem is that there can be two folders with exactly the same name - one inside the SourceFolder, one outside. Since the test looks only at the name, it can be "fooled" if the outside folder is selected. It took me a while to get this straightened out (it's amazing how quickly one gets rusty when not practicing) but I think I finally got it: tell application "Finder" set subFolders to every folder of entire contents of SourceFolder as alias list if TargetFolder is in subFolders then ... else ... end if end tell 1
BonB Posted November 14, 2013 Author Posted November 14, 2013 Oh, the name is exact. The problem is that there can be two folders with exactly the same name - one inside the SourceFolder, one outside. Since the test looks only at the name, it can be "fooled" if the outside folder is selected. It took me a while to get this straightened out (it's amazing how quickly one gets rusty when not practicing) but I think I finally got it: tell application "Finder" set subFolders to every folder of entire contents of SourceFolder as alias list if TargetFolder is in subFolders then ... else ... end if end tell thank you so much. I will try this later and I really appreciate your time and effort. It's great help.
Recommended Posts
This topic is 4026 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now