Jump to content
Server Maintenance This Week. ×

Creating a folder alias with applescript


This topic is 5222 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I am trying to run an applescript (below) from within a filemaker script where the first set of quotes (which is the patch "David:Documents:test:xfer") is the value of a filemaker field. I have done this before with: set x to cell "myField" of current record... and a do shell script command, but that does not seem to work here.

Any help here would much appreciated. Also should I be using Native AppleScript of Calculated AppleScript?

set folder_to_alias to "David:Documents:test:xfer" as alias

tell application "Finder" to make new alias file at desktop to folder_to_alias

Link to comment
Share on other sites

Where's the 1st part of the file path, "Macintosh HD:Users:"? Or whatever your drive name is. Or use a variable to build the path, which will dynamically include the short user name:

set doc_path to path to documents folder as Unicode text

set folder_to_alias to doc_path & "Scripts" as alias

tell application "Finder" to make new alias file at desktop to folder_to_alias

Link to comment
Share on other sites

Hi Fenton

Not quite understanding this.

1. If I set a variable for the path (variablePath), how do I add that variable into the applescript?

2. What is "Scripts" supposed to indicate? I am running this as a script, using the perform applescript command set to NativeAppleScript.

Thanks

David

Link to comment
Share on other sites

This works, but how do I change the path of "myServer:myFolder:mySubfolder" to a variable or a field in filemaker.

set doc_path to path to "myServer:myFolder:mySubfolder"

set folder_to_alias to doc_path as alias

tell application "Finder" to make new alias file at desktop to folder_to_alias

Link to comment
Share on other sites

It's confusing talking about FileMaker, AppleScript and the OS in one short post.

I guess I shouldn't have used the word "variable" without clarification. Since we were talking about AppleScript, I meant an "AppleScript variable" (like "doc_path" in your AppleScript). Normally I used the phrase "script Variable" when talking about a FileMaker script Variable.

"Scripts" is just the name of a folder in my Documents folder. You likely have it also.

Link to comment
Share on other sites

It is a good question, whether to run this via a calculation, or using native AppleScript (entered directly in the Perform AppleScript dialog). I usually use the later, but in cases where the script is short, a calculation can be better. Because, if you just enter the AppleScript you have to know something about the object hierarchy of FileMaker's AppleScript, in order to get access to a field's value. Or you have to first go to a layout and record with the field on it; then AppleScript can always get it easily.

The advantage of running via the (•) Calculated AppleScript option is that FileMaker will get the value for you, and pass it to the AppleScript. And you already know the rules for FileMaker access to the field. The disadvantage is the you have escape quotes and insert line breaks where needed.

I suggest building the entire AppleScript in a single unstored calculation field. Then look at the result on a layout. You will see any problems. You still need FileMaker access to that calculation field, but it does not need to be on the current layout, nor do you need to hard-code its layout or table occurrence name (which you might otherwise).

"set folder_to_alias to alias " & Quote ( Server_Path ) & ¶ &

"tell application "Finder" to make new alias file at desktop to folder_to_alias"

[P.S. the above takes the server path from a field. But you could just type it directly into the calculation, escaping the quotes, like I did with "Finder"]

Link to comment
Share on other sites

  • 1 year later...
  • Newbies

I'm stuck at the same roadblock. I'm creating a database that a group of people can use to look up their "speaker numbers" for an event, and press a button to create a folder on the desktop that's already named with their last name and speaker number. Overwriting isn't an issue, we just want ease of use.

Here's what I have so far:

tell application "Finder"

make new folder at alias "(path)" with properties

{name:"DATABASE::LASTNAME"}

end tell

When I plug in other values for the name, it works just fine. I can't however get it to plug in values from the current record. Can anyone help me?

Thanks,

Brian

Link to comment
Share on other sites

This is how I might create a folder on the Desktop, based on a FileMaker field, if it was in a Perform AppleScript step:

--tell application "FileMaker Pro Advanced"

set folder_name to cell "NameLast" of current record

--end tell

set DT to path to desktop

tell application "Finder"

try

make new folder at DT with properties {name:folder_name}

end try

end tell

You'll notice that the "tell FileMaker" commands are commented out, when using inside FileMaker. If used (or edited) in AppleScript Editor, you'd uncomment those 2 lines. Notice also that the call to FileMaker is NOT inside the Finder tell block. In the above case the field "NameLast" must be on the current layout also. Otherwise you could get it, but you'd have to specify the layout or table (table occurrence) name. On the layout is easiest (and in this case likely). Notice also there are no quotes around "folder_name". It's an AppleScript variable, so it does not need them.

The "path to Desktop" is not in the Finder tell block either. It does not like it. However, if all you're doing is creating a folder on the desktop, with no further addition to that, then the Finder (and I think only the Finder) can target it directly, like this:

--tell application "FileMaker Pro Advanced"

set folder_name to cell "NameLast" of current record

--end tell

tell application "Finder"

try

make new folder at desktop with properties {name:folder_name}

end try

end tell

P.S. The "try" is because it is an error to overwrite an existing folder; AppleScript will not overwrite a folder. With "try" it will just not display the error (nor overwrite).

Edited by Guest
Link to comment
Share on other sites

I prefer to do this a little differently, for troubleshooting purposes

Set variable [ $mydata; substitute( relation::fieldname; " "; " ")]

# escape spaces

Set variable [ $myscript: "do shell script 'mkdir -p ~/desktop/myFolder' "

Set variable [ $myscript ; substitute( $myscript; "myfolder"; $mydata]

Perform applescript [ $myscript ]

Not if $mydata contains "aa/bb/cc/theFolder" all intermediate folders will be created automatically and with -p any existing folders will get overwritten.

Edited by Guest
Link to comment
Share on other sites

  • 3 months later...

I used your applescript code to create a folder and it worked great!! This is the one I used, since my folder will always go to the desktop.

tell application "Finder"

try

make new folder at desktop with properties {name:folder_name}

end try

end tell

Wonder if you have a simple solution like this that will delete a folder from the desktop, or delete the files in the folder??

The folder will always be the same name.

Thanks.

Link to comment
Share on other sites

This topic is 5222 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.