preference file

I don’t know if this is the right place to post this question.

I mainly use XOJO as a GUI for all my Applescripts. So the user clicks a button and folders open. I made a script that gets username and password text from a text field and makes a text file and saves the file. This file is at the root of the user home directory. Another button reads the ID & PW and mounts servers.

Is is possible to get the path to where ever the XOJO app is running from so I can read and write to the text file within the app itself.

App.ExecutableFile.NativePath f.e.

Found here: http://documentation.xojo.com/index.php/Application

You can READ from file in the Apps resources, but you CANNOT write to them

I came up with this to get the path, so I guess I can plug in a filename for the ID and PW.

[code]set text item delimiters to {":"}

tell application “Finder”
set pPath to path to me as text
–display dialog pPath

-- get path
set the_path to text items 1 thru -2 of "Macintosh HD:Users:shawn:Desktop:QNAP v1.9.app:Contents:Resources:path2me.scpt"
display dialog the_path as string
-- the_path = Macintosh HD:Users:shawn:Desktop:QNAP v1.9.app:Contents:Resources

end tell

set text item delimiters to {""}
[/code]

Shawn - You should be using SpecialFolder.Preferences.Child(“YOUR_APP_PREF_NAME”) to save and read app preferences. Writing to a file within the app’s bundle will get your app flagged as bad in a number of ways.

Maybe, this is of interest for you: classPreferences - A cross platform preferences class for Xojo using SQLite

Use TPSF to get the proper location for your app support directory. You cannot write to SpecialFolder.Preferences on Mac.
https://github.com/devtimi/TPSF

On macOS either store your preferences in your Application Support folder or use NSDefaults to let the OS handle it for you…
I have a simple preference class, that mimics the dictionary syntax and saves out to JSON files…
https://bitbucket.org/shaosean/xf/downloads/XFUserDefaults_1.0.0.zip

thanks for all the help, I have no idea what any of this means. If anyone wants to teach me how to use SpecialFolder.Preferences.Child I’m all ears.

What is so wrong about making a text file with line 1 user name, line 2 is password. This is for me and 3 Mac users at work. Not for world wide distribution. Currently my applescript creates a text file in the users home folder, and writes and reads from the file. Just trying to make the app as cool as possible.

If they are not encrypted, why use Passwords anyway?

Nothing wrong with this. But the Users Home Folder is not ment for Config./Settings Files, There’s a dedicated (on Windows 2 if you count the Registry) area for such Files.

classPreferences offers an easy to use way to read/write Settings to where they should be saved.

its just a simple text file to store 2 words, teach me tell me another better way and I’m all ears. thanks. I’ll read up on classPreferences

I’ll never figure this out.

link text

this is why I use Applescript, 6 lines…not 300

set theFile to (path to home folder as string) & “passwords.txt”
set fileHandle to open for access theFile
set x to (read fileHandle) as string
delay 1
set the clipboard to x

close access fileHandle
delay 1
the clipboard

  1. Drag&Drop the classPreferences File into your Xojo Project
  2. Add a Property of classPreferences to your Project
  3. Use “Preferences = new classPreferences(“PreferencesTest”)” in your App.Open Event to tell your classPreferences Object in which Folder to save the Settings (will be created automatically if it does not exist)
  4. Use Lines like “Object.Value = App.Preferences.getBooleanValue(“check”,true)” or “App.Preferences.setBooleanValue(“check”,Object.Value)” anywhere in your Project to get/set Values of various Types in your Settings File.

Or in other Words. After you’ve added the class, you need 2-3 Lines to create the Settings File and to read/write Settings.

thank you very much Sascha

[quote=352964:@Shawn Brady]this is why I use Applescript, 6 lines…not 300

set theFile to (path to home folder as string) & “passwords.txt”
set fileHandle to open for access theFile
set x to (read fileHandle) as string
delay 1
set the clipboard to x

close access fileHandle
delay 1
the clipboard[/quote]

I mean… if that’s all you want to do then you can do it in Xojo in 6 lines as well…

dim t as TextInputStream = TextInputStream.Open(SpecialFolder.UserHome.Child("passwords.txt")) dim x as String = t.ReadAll t.Close dim c as new Clipboard c.Text = x c.Close

[quote]I mean… if that’s all you want to do then you can do it in Xojo in 6 lines as well…

dim t as TextInputStream = TextInputStream.Open(SpecialFolder.UserHome.Child(“passwords.txt”))
dim x as String = t.ReadAll
t.Close
dim c as new Clipboard
c.Text = x
c.Close[/quote]

Just keep the file in

specialfolder.applicationsupport.child(“Myapp”) folder
or
specialfolder.documents.child(“Myapp”) folder

These are free for you to write in. Works everywhere.

Not userhome
Not preferences
Not applications
Not the resources folder of your app.

Dont ask why Apple dont want you to write preferences into a folder named preferences. That way madness lies.

But then again, writing passwords unencrypted into a file called passwords is like leaving a bag of money on the lawn.