Need to save (and later read) a saved preference__

Hello,

I have a folder template creation script, that copies an already created folder structure from one location to another preset location and renames it based on user input, along with a docket number:

--destParent is final location of Project Folders
global dest
set dest to "Geezer:_PROJECTS:"

--srcTemplate is location of project template folder
global srcTemplate
set srcTemplate to "Geezer:Templates:Project_Template_Single:"

global template
set template to "Project_Template_Single" as string

--projName is name of intended new project


tell application "Finder"
	activate
	set theResult to display dialog "New Project Name:" default answer "" buttons {"Cancel", "Create"} default button 2
	set theDocketResult to display dialog "Please enter the docket number:" default answer "" buttons {"Cancel", "Create"} default button 2
	
	if button returned of theResult is "Create" then
		set projName to ((text returned of theDocketResult) & "_" & (text returned of theResult)) as string
		duplicate srcTemplate to dest
		set name of (folder template of folder dest) to projName
		select (folder projName of folder dest)
	end if
end tell

one of the subfolders of projName is “Web”. What i’ld eventually like to add to the above script is the ability to ask the user if they want to create a new client folder on our webhost. I’m not sure how i’m going to do this yet, but one thing i thought about doing is to ask, in the above script, if the user wants to create a web folder, and if yes, get the intended name, and store it in the Web subfolder of the newly created folder structure projName. I seem to be getting stuck finding the path to this location though.

I want to save the name of the intended web folder so that i can create it using a shell script(?) or perhaps Panic’s Transmit software. Also, I would like to use it for future uses such as synchronizing to the web folder, etc.

Try something like this:

property dest : "Geezer:_PROJECTS:"
property template : "Geezer:Templates:Project_Template_Single:"

tell application "Finder"
	activate
	
	repeat
		display dialog "New project name:" default answer "Test" buttons {"Cancel", "Continue."} default button 2
		set projectName to (text returned of result)
		if result is not "" then exit repeat
	end repeat
	
	repeat
		display dialog "Docket number:" default answer "0" buttons {"Cancel", "Continue."} default button 2
		set docketNum to (text returned of result)
		if result is not "" then exit repeat
	end repeat
	
	set projectName to docketNum & "_" & projectName
	
	try
		make new folder at folder dest with properties {name:projectName}
		set projectFolder to result
		
		duplicate every folder in folder template to (result)
	on error errorMsg number errorNum
		display dialog "Error (" & errorNum & "):" & return & return & errorMsg buttons "Cancel" default button 1 with icon caution
	end try
	
	display dialog "Template copied successfully." buttons {"Add Web Folder", "Cancel", "Select Project"} default button 3
	
	if (button returned of result) is "Add Web Folder" then
		repeat
			display dialog "Web folder name:" default answer "Web Test" buttons {"Cancel", "Create"} default button 2
			set webSubfolderName to (text returned of result)
			if result is not "" then exit repeat
		end repeat
		
		make new folder at folder "Web" of projectFolder with properties {name:webSubfolderName}
	end if
	
	select projectFolder
end tell

thanks so much - you even cleaned up my messy code… If i could, i’ld buy you a beer!

The only small thing is that i’m looking for a way to save the data in websubfolderName to a text file saved in folder “Web” of projectFolder, as opposed to created a new folder called websubfoldername.

Get rid of the “make new folder at folder “Web”.” line, and replace it with something like this:

do shell script "echo " & quoted form of webSubfolderName & " >> " & quoted form of (POSIX path of (folder "Web" of projectFolder as alias) & "yourTextFileName.txt")

thanks!

I had already figured out how to create a file “webdata.txt” via calling this subroutine which i added;


on writeToFile(theFile, webFolderName)
	--creates the text file
	try
		open for access theFile with write permission
		set eof of theFile to 0
		write (webFolderName) to theFile starting at eof
		close access theFile
	on error
		try
			close access theFile
		end try
	end try
end writeToFile

which works okay - it gives me a resultant file with just one line with the “webFolderName.” However, when i go to read it back with this next script, i get an End of File error:

tell application "Finder"
	activate
	set thePath to container of (path to me) as string
	set theWebFolder to (read alias (thePath & "webdata.txt"))
	set thePath to POSIX path of thePath
	my goToLocalFolder(thePath, theWebFolder)
	
	
end tell

on goToLocalFolder(thePath, theWebFolder)
	tell application "Transmit"
		-- Create a new session window for the script
		set theDoc to (make new document at end)
		
		-- send commands to the frontmost document window
		
		tell current session of theDoc
			--connect to "server" as user "user" with initial "path" with password "blah"
			connect to "server" as user "user" with initial path "public_html/clients" with password "pass"
			set your stuff to thePath
			set their stuff to theWebFolder
		end tell
	end tell
end goToLocalFolder

I also seem to be having issues with the the file webdata.txt being left in use.

Should I just replace with the do shell echo script?

thanks to your help on this forum, i have succesfully been able to store a variable into a text file, called “webdata.txt” The code I’m using to do this is as follows:

on writeToFile(theFile, webFolderName)
	--creates the text file
	try
		open for access theFile with write permission
		set eof of theFile to 0
		--write ((webFolderName) & return) to theFile starting at eof
		write (webFolderName & return) to theFile starting at eof
		close access theFile
	on error
		try
			close access theFile
		end try
	end try
end writeToFile


and later i’m reading this using this following code in another script:

set theData to read alias (thePath & “webdata.txt”)

and then using theData in Transmit using this following code:


on goToLocalFolder(thePath, theData)
	tell application "Transmit"
		-- Create a new session window for the script
		set theDoc to (make new document at end)
		
		-- send commands to the frontmost document window
		
		tell current session of theDoc
			connect to "server" as user "user" with initial "path" with password "blah"
			set your stuff to thePath
			set their stuff to theData
		end tell
	end tell
end goToLocalFolder

It seems like its mostly working - Transmit changes to my local folder thePath, but “their stuff” doesn’t properly change into the intended folder specified in theData. If i change the line ‘set their stuff to theData’ into set their stuff to “test”, then it will take me there.

I think it might have to do with the way the variable is either stored in, or read back from, webdata.txt

Any hints?

I’ve since further discovered that if I manually type “test” into the file webdata.txt and save the file, the applescript which reads the file and controls transmit works perfectly.

So it must be the way I’m writing to the file in the first place. Please Help (before I go insane)!