1: create an applescript that will create a folder (same name/location every time)
2: Run a JavaScript program that will ultimately fill that folder with *.txt files
3: run another applescript that will combine those *.txt files into a single “combined.txt” file
4: import that data into FileMaker Pro
5: delete the folder that contains the already imported text files
6: replace that folder with an empty folder of the same name. (allowing the JavaScript program to dump it’s text files again the next time).
most of this is working already. But I’m having trouble with the concept of file & folder paths.
I’ve read posts about references to “theFile” or “theFolder” where a user indicates the name of the object. But how does applescript “know” where to look. For example, what if there are multiple files or folders with that name. I haven’t seen directories or paths being mentioned in any of these.
In my above example, I need to delete and create specific folders that will always be in the same location (from “root”, as the computer it is run on may change). In OS X, how do I indicate that it needs to create a folder in ~/Applications/NEWFOLDER/ and delete that same folder ~/Applications/NEWFOLDER/ ? Where “~” would be the hard drive of the mac that the script is running on.
ALL HELP IS GREATLY APPRECIATED. MAY MANY BLESSINGS FALL YOUR WAY!
set theFolder to choose folder
tell application "Finder"
open theFolder
end tell
Applescript now knows where to find theFolder because this opens a dialog that the user directly tells AS “here is this folder that I call theFolder”
The “path to” command has limited use for use on different volumes. It uses constants, and you can’t say "path to “mySpecificFolder”
you can use -
path to me (path to the script itself)
path to desktop folder
path to preferences
and there are others. I use this sometimes if I have a script needs to know where it is, and will be used on different volumes.
If you want to use different volumes but the paths stay the same, you can hardwire the paths with the root as a variable.
set Vols to list disks--gives you the "roots" as you called them
set Disk2 to item 2 of Vols--gets the name of disk 2 on my comp as example
set Loc to ":Users:admin:Desktop:Downloads"--set a path without root
set Loc2 to Disk2 & Loc as string-- sets a path defined as "Disk2:Loc" which AS reads as "HardDisk:Users:admin:Desktop:Downloads"
tell application "Finder"
open Loc2--I put this here to test my hardwired reference. This opens the new location.
end tell
I think I follow you, but I’m not clear on the “Disk2” reference. I think what I’ll always be doing in my scenerio is using a folder in the “Applications” which is always immediately under the startup disk. In AS, is “:” used instead of “/” to separate folder structure?
(for example: Hard Drive:Applications:MyProgram:SavedFiles vs. HardDrive/Applications/MyProgram/SavedFiles) which one is used?
I’ve scoured the AppleScript Language PDF and haven’t found any clear answers on this topic of folder structure/paths.
Before we do all this folder creation-deletion activity, what’s the goal?
1: create an applescript that will create a folder in Applications folder (same name/location every time)
2: Run a JavaScript program that will ultimately fill that folder with *.txt files
3: run another applescript that will combine those *.txt files into a single “combined.txt” file
4: import that data into FileMaker Pro
5: delete the folder that contains the already imported text files
6: replace that folder with an empty folder of the same name. (allowing the JavaScript program to dump it’s text files again the next time).
Looks like you need:
A stationary folder that resides in your Applications folder. Let’s call it ‘FileMaker TextTemp’. The folder will be filled with text files that will be combined into one text file. The data is sent to Filemaker Pro. *The combined text file is deleted and stationary folder ‘FileMaker TextTemp’ is ready to receive.
When you create the combined (appended) text file it will have a reference name. My question is why create and delete the folder, instead of deleting only the combined text file?
SC
Because I want to be sure that all of the data is valid (current). I will be handing this system off to someone else. One of the ways they will know where the are is by confirming they have an empty folder to start with. I’m afraid that if there is an “appended” file in the folder, they may forget whether it is new or old.
(The processes may not happen all in one day)
If they see that the folder is empty, it will be a hint to them that they need to gather the data, then append. Make sense?
After this post, back to your script writing…which I’ve mostly worked out and then brought me to that last question.
Won’t there be an appended file anyway?:
3: run another applescript that will combine those *.txt files into a single “combined.txt” file <-This is the appended file
4: import that data into FileMaker Pro<- after importing, couldn’t we delete the file, making the folder “empty”. You could then program an action letting you know the folder is ready to recieve again, ie open the folder’s window, bring up a dialog?******
5: delete the folder that contains the already imported text files
6: replace that folder with an empty folder of the same name. (allowing the JavaScript program to dump it’s text files again the next time).<-The reason I’m stopping here is because this could create confusion as well. I think what your saying is that if the old folder is deleted it is easier for all to see that a “new” folder has come with “new” info?
Remember, there are other ways to “alert” that the folder is empty and ready to recieve the next batch of .txt files, avoiding a bit of code that creates and deletes a folder. Sorry to ask you to consider a second time, so after this its “as you wish”
SC
Most OS X apps will expect an alias or a file, both of which use a colon (e.g. “Mac HD:Applications:SomeFolder:”).
You will also see POSIX (aka Unix-style) paths, which use a [forward] slash (e.g. “/Applications/SomeFolder”). This is needed* when you are using the “do shell script” command, among other things.
Visit this page to see how to convert between the two forms.
Don’t use the tilde (~) to refer to the startup drive. The tilde is used in Unix (and thus, POSIX paths) to refer to the current user’s home folder.
Here’s an example of making/deleting a folder with the Finder:
tell application "Finder" to make new folder at (path to applications folder) with properties {name:"SomeFolder"}
tell application "Finder" to delete (((path to applications folder) as text) & "SomeFolder") as alias
Here’s an example of making/deleting a folder with “do shell script”:
In addition to previous posts, you can use something like this to make the folderl or check if one exists:
property folder_name : “My Folder”
– get a reference to the local “Applications” folder
set apps_ref to (path to “apps” from local domain)
– check for folder existance
– if it doesn’t exist, then make a new folder
try
set folder_ref to (“” & apps_ref & folder_name) as alias
on error – there is no folder
tell application “Finder”
set folder_ref to (make folder at apps_ref with properties ¬
{name:folder_name}) as alias
end tell
end try