opening a user choosen file


tell application "BBEdit"
	activate
	open {file "Macintosh HD:Users:applecomputer:Documents:propertynut.com:Pnut Adds (txt files):find[10].txt"} with LF translation

Is there a way to open a file this defined or choosen by the user. The file names will be named different. So I would like to be able to open a file that I choose and than run the commands that are wrote in the script. It will than save the file to a different folder with the same name as the original. The original files will always be in the same folder and it will always save into the same folder. Just the file names will be different. Any ideas on how to make this happen.

Thanks
-J

Hi,

try this

set myFile to choose file without invisibles
tell application "BBEdit"
	activate
	open myFile with LF translation
end tell

I will give that a run and see if it turns out to what I am thinking.

Thanks
-J

That worked perfectly. I have one problem now. When I run the save command I need it to save with the current name of the file that was choosen by the user and save it to a different folder. This is the script that I was using but it doesn’t seem to save it as with the current opened files name. Not sure what I am doing with that.


set myFile to choose file without invisibles
tell application "BBEdit"
	activate
	open myFile with LF translation
	(a few command lines are here)
	save text document 1 to file "Macintosh HD:(path to the folder): "
	close text window 1
end tell

I guess I have not figured out how to get it to save with the current file name into the folder I have defined.

try this

set myFile to choose file without invisibles
set fName to name of (info for myFile)
tell application "BBEdit"
	activate
	open myFile with LF translation
	-- 	(a few command lines are here)
	save text document 1 to file ((path to documents folder as Unicode text) & fName)
	close text window 1 saving no
end tell

Stefan

That worked out perfectly for me. I just have one question, why do you ad this line (as Unicode text). This is more just a for my understanding. I don’t quite understand all of the applescript stuff but I am trying to get there. Again thanks for the help!

-Jared

path to documents folder results an alias but we need a string path.
path to documents folder as Unicode text results an Unicode text path, because Unicode text is the default text class for folder and file names