hey, i was trying to set the directory of a folder (such as Macintosh HD:Users:) to a varriable (this folder) using the choose folder with prompt thing, and i couldent work out how to do it. any suggestions?
Hi,
set thisFolder to (choose folder)
--> result: the alias of the folder
set thisFolder to (choose folder) as text
--> result: the string path of the folder
ok, first ones working.
now, would you be able to help me with something else?
I want the script to read a text file at a directory, and replace the first line of text with something written into a dialog box
I also want a script that will read the first line and set it to a varriable.
also, how do you make a dialog box be a password box? with dots instead of text?
also, i want to move the chosen file to a directory.
try this, it contains all elements of your request.
It expects a plain text file test.txt on desktop.
The script changes the first line and moves the file to the home folder of the current user
set theTextFile to ((path to desktop as text) & "test.txt")
set theDialog to (display dialog "enter some text" default answer "" with hidden answer)
set newFirstLine to text returned of theDialog
try
set ff to open for access file theTextFile with write permission
set theText to paragraphs of (read ff)
set item 1 of theText to newFirstLine
set {TID, text item delimiters} to {text item delimiters, return}
set theText to theText as text
set text item delimiters to TID
set eof ff to 0
write theText to ff
close access ff
on error
try
close access file theTextFile
end try
end try
tell application "Finder" to move file theTextFile to home
ok, can you help me fix some things?
First, there should be a dialog box with 3 buttons, change password, cancel, enter password. if you click change password then:
I would like there to be two dialog boxes, like the one at the start, but after the first one it sets the text returned to a varriable, and then checks to see if the second one is identical too the first one. if they are the same, it overwrites the first line of the test.txt, then go’s back to the start.
should you click cancel, it quits the app
if you click the enter password, it comes up with another hidden answer thing. it then checks the first line of test.txt, and if the two are identical, opens a folder.
also, with the directory’s, could you write them as the actual directory’s? That would be best for me.
thanks.
a custom dialog box can be realized with this syntax
set theDialog to (display dialog "enter some text" default answer "" buttons {"Change Password", "Cancel", "Enter Password"} with hidden answer)
set {text returned:textReturned, button returned:buttonReturned} to theDialog
if buttonReturned is "Enter Password" then
-- do something
else if buttonReturned is "Change Password" then
-- do something else
end if
Pressing the Cancel button quits the script automatically
There is no actual directory in AppleScript. You have always to specify it
no, i mean in the actual script, can there be something like “Macintosh HD:Users” rather than “path to desktop as text”
I tried it myself, and it’s moving ok, but it’s not writing.
path to home folder
returns the alias to the home folder of the current user
dose it have to be like that? i want to be able to change it (in script editor) myself, and using just a directory is all i can do
you can also use just a literal string path
set theTextFile to "MacHD:Users:myUser:path:to:test.txt"
ok, some problems.
how to i get the script to just read the first line of test.txt and set it to a varriable, to compare it to the inputed text.
also, can you divide the large script into two, writing the text inputed as one script, and reading the first line and setting it to a varriable.
also, with the directory, is there something like this “((path to desktop as text) & “test.txt”)” but instead of path to desktop, i want it to be (because it will eventually be an app) to be set to the contents folder, is that possible?
also, this has stopped writing to the text file, why? i want it to check that both inputted text’s are the same, then write that
set theDialog to (display dialog "Enter new Password" default answer "" with hidden answer)
display dialog "Enter new Password again" default answer "" with hidden answer
if the text returned of the result is equal to theDialog then
set theTextFile to "Macintosh HD:Users:user:desktop:test.txt"
set newFirstLine to text returned of theDialog
try
set ff to open for access file theTextFile with write permission
set theText to paragraphs of (read ff)
set item 1 of theText to newFirstLine
set {TID, text item delimiters} to {text item delimiters, return}
set theText to theText as text
set text item delimiters to TID
set eof ff to 0
write theText to ff
close access ff
on error
try
close access file theTextFile
end try
end try
end if
set theTextFile to ((path to me as text) & "Contents:test.txt")
refers to the folder Contents of the script or application bundle
This reads and compares the text
set theTextFile to ((path to me as text) & "Contents:test.txt")
set theDialog to (display dialog "enter some text" default answer "" with hidden answer)
set enteredText to text returned of theDialog
set theText to paragraph 1 of (read file theTextFile)
if enteredText is theText then
say enteredText & " matches"
else
say enteredText & " does not match"
end if
Probably it is possible to divide the script into two.
if you want to save a password in the text file, consider that everybody can open the bundle and open the text file
Do you know how to save a file as a hidden file? applescipt can read a hidden folder, and this file will be in a hidden folder, in the application.
and can you write the change text from the text input, with 2 inputs and if they are the same it sets the text returned of the result to the first line of the text?
you can hide a file or folder by adding a dot at the beginning of the name,
but a hidden file is not really a secure solution. Terminal.app shows hidden files by default.
Better use the keychain or at least use a routine to encrypt the crucial data
keychain? what?
and whats a routine?
how do i use the encryption routine?