probably another ridiculously simple fix.
i have a script that works quite well - it allows the user to choose a .swf file, then creates an html file with the chosen file linked. these two files are then uploaded via ftp to a webserver. This may not make a lot of sense, but there is a useful purpose for this! 
my problem is this: although i can choose a .swf file from anywhere, the resulting html file is simply saved to the desktop, and the script then looks for both files (for the ftp transfer) on the desktop. so what i want is to be able to select a file from anywhere, have the script remember that path (i guess the parent path?) as a variable, save the html file to the same directory, and then again look to that directory to upload the two files. i guess the key here is that once i choose a file, i need the appropriate path set as a variable.
i have searched through the posting here and found several examples of scripts that i think are very close… unfortunately i have not been able to make any of them work.
any help would be appreciated!
Is this what you are looking for?
set a to choose file
set file_Path to (a as text)
--> "TreeHouse:Users:casdvm:Documents:Family:RobSciFair08.xls"
set posix_file_Path to POSIX path of file_Path
--> "/Users/casdvm/Documents/Family/RobSciFair08.xls"
Thanks!
This works well, except the path it returns is to the file directly (ie. “/Users/Admin/Desktop/TestFile.swf”). Is there any way to back it up to the directory level? (ie. just the “/Users/Admin/Desktop/”)
Hi,
if the target directory is always the desktop, you can reference it directly with
set HFS_desktop to path to desktop as text --> "[startup disk]:Users:[current user]:Desktop:
set POSIX_desktop to POSIX path of (path to desktop) --> "/Users/[current user]/Desktop/
This is one way to strip the file name of a path
set a to choose file
set file_Name to name of (info for a)
Thanks Stefan, unfortunately i may have chosen a bad example - the desktop is where the file resides now (i’ve was able to get that working easily). I would prefer to be able to select the file from any directory, and have the path to that directory saved as a variable which could then in turn be used to save other files and eventually find the two files that need uploading via ftp.
two ways
set a to choose file
tell application "Finder" to set targetDirectory to container of a as text
set a to (choose file) as text
set {TID, text item delimiters} to {text item delimiters, ":"}
set targetDirectory to ((text items 1 thru -2 of a) as text) & ":"
set text item delimiters to TID
Nice. that’s done it! thanks!!