hi all
not a coder here im afraid BUT can anyone help me this scenario?
i want to create a application script that opens a dialog box saying something like ‘Job Notes’ then i will enter some text, then i want it to save as a text file within a specific folder onf my choice.
any help greatly appreciated!
KL
Hi,
simple solution
set {text returned:jobNotes} to display dialog "Enter Job Notes" default answer return & return & return
set destinationFile to choose file name
try
set fileReference to open for access destinationFile with write permission
write jobNotes to fileReference
close access fileReference
on error
try
close access destinationFile
end try
end try
thats great thanks stefan, one more thing. if i wanted to implement that to this existing piece of script?
tell application “Finder”
set JobName to text returned of (display dialog “Please enter Job Name:” default answer “Job_Name”)
set loc to choose folder “Choose Parent Folder Location”
set newfoldername to JobName
set newfo to make new folder at loc with properties {name:newfoldername}
make new folder at newfo with properties {name:“Links”}
make new folder at newfo with properties {name:“Supplied”}
make new folder at newfo with properties {name:“Output”}
make new folder at newfo with properties {name:“Previous”}
make new folder at newfo with properties {name:“Workings”}
end tell
so first the job name dialog appears from script above, then the destination selection for saving these folders, then next dialog maybe - Are there any Job notes ? :, two options maybe - if, YES, then that entry uses your script to put into another folder called job notes, in the same directory of the other folders??
If there are no job notes, somehow the script just finishes.???
but still retaining the other folders in the original chosen destination.
hope that makes sense?!!
thanks v much.
KL
try this, the mkdir line creates the directories much easier and faster
To save the job notes click “Continue” otherwise “Skip”, “Cancel” aborts the script
set {text returned:JobName} to display dialog "Please enter Job Name:" default answer "Job_Name"
set baseFolder to choose folder "Choose Parent Folder Location"
set {text returned:jobNotes, button returned:buttonReturned} to display dialog "Enter Job Notes (optional)" default answer return & return & return buttons {"Cancel", "Skip", "Continue"}
do shell script "/bin/mkdir -p " & quoted form of POSIX path of baseFolder & quoted form of JobName & "/{Links,Supplied,Output,Previous,Workings}"
if buttonReturned is "Continue" then
set jobNotesFile to (baseFolder as text) & JobName & ":Job Notes.txt"
try
set fileReference to open for access file jobNotesFile with write permission
write jobNotes to fileReference
close access fileReference
on error
try
close access file jobNotesFile
end try
end try
end if
amazing…
can we get the text file into a folder called job notes?
as eventually i will want only 1 file outside the sub folders
thanks again
KL
sure
set {text returned:JobName} to display dialog "Please enter Job Name:" default answer "Job_Name"
set baseFolder to choose folder "Choose Parent Folder Location"
set {text returned:jobNotes, button returned:buttonReturned} to display dialog "Enter Job Notes (optional)" default answer return & return & return buttons {"Cancel", "Skip", "Continue"}
set subFolders to "/{Links,Supplied,Output,Previous,Workings"
if buttonReturned is "Continue" then set subFolders to subFolders & ",'job notes'"
set subFolders to subFolders & "}"
do shell script "/bin/mkdir -p " & quoted form of POSIX path of baseFolder & quoted form of JobName & subFolders
if buttonReturned is "Continue" then
set jobNotesFile to (baseFolder as text) & JobName & ":job notes:Job Notes.txt"
try
set fileReference to open for access file jobNotesFile with write permission
write jobNotes to fileReference
close access fileReference
on error
try
close access file jobNotesFile
end try
end try
end if
nice…
hope im not taking the biscuit here, just one more request!!!
i had a thought, is there a way you can automatically add the time and date to the text file of the job note of when it was created ?
thanks
KL
change the write line
.
write (current date) as text & return & return & jobNotes to fileReference
.
hi
ive tried to position this line within the script, in some positions it errors but in other positions, the script completes but i dont see a date in the text file?
KL
I forgot a pair of parentheses
replace
write jobNotes to fileReference
with
write ((current date) as text) & return & return & jobNotes to fileReference
perfect, you are superhero status now!
KL