Reading from a text file

I currently have a text file with a folder with full path on a text file.
I can read the file and get the full path as a string from the text file but I can’t take that and have the “Finder” open that folder.


set myPrefsFile to choose file
open for access myPrefsFile
set prefContents to read myPrefsFile using delimiter {return}
close access myPrefsFile
set txtvar1 to item 1 of prefContents
set txtvar2 to item 2 of prefContents


tell application "Finder"
	open alias txtvar1
	activate
end tell

when i return txtvar1 I get “volume one:Users:me:Documents:acrobat:”
any ideas

Thanks John

would it help if I changed the format of the text to a unix file form
ie - /Users/me/Documents/Acrobat

Hi,

Try changing:

set txtvar1 to item 1 of prefContents

to:

set txtvar1 to (item 1 of prefContents) as string

gl,

This has been posted I don’t know how many times now: you don’t need to open a file to simply read it, only when you are writing to it. Also, another thing covered many times, since Mac OS X is based on Unix, you can’t really rely on line endings being delimited with a return character. AppleScript can handle this for you by simply breaking text into paragraphs and let it figure out the line endings. AppleScript also has a try command that will report an error if there is one, so use it. Finally, without posting the actual contents of the paragraph in question, it’s nearly impossible to know why the command is failing. The Finder wants a Mac style (i.e., colon delimited) path for file and alias references, not a POSIX path (i.e., forward slash delimited). Try this, and if you get errors post the error and the actual content of the file chosen.

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Jonn8;

Do you have a nice little script or concise method for using your “Convert Script” script? My results never look quite as clean as yours do when I’m posting to a forum.

NovaScotian

When preparing my scripts, I make them as clean as I can in Script Editor before running the the “Convert Script to Markup Code” app. That means taking out extraneous har returns, etc. Then, in the “Convert Script to Markup Code” app, I set it to convert to BBCode and include an AS URL Protocol Link that is Opened in a New Window. In the “Convert Script to Markup Code” app preferences, for BBCode conversions, I set the header to: [ quote] and the footer to [ /quote] (note: I’ve added spaces after the opening bracket here so the codes won’t be interpreted as codes in this post only, don’t add those spaces in the app prefs), add my name as a signature and include the credit link (I think those are the defaults). No post processing. I then just paste the result into my post on the BBS.

Jon

In the next version of this BBS, if all goes according to plan, there will be a built-in syntax color parser for AS code which will obviate the need for using my app (for this BBS at least).

Jon

jonn8
after trying the code the error message I got was

the txt file contains

volume one:Users:me:Documents:Acrobat
WorkProjects:files:

As you can tell I’m new to this and most of my knowledge has come from books.
They never wrote of being able to use paragraph as a seperator. Or that I didn’t have to get access to the file to read.

thanks for the help

When I follow those directions exactly (I think) I get a flat, left-adjusted display like this. What have I missed?


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Hmm, I don’t know. What version of my app are you using? (The latest is v2.7.1.) Are you using Script Editor? Which version? What type of browser are you using to post? When I convert my scripts, the tabs are retained as set in Script Editor and when posted as part of a quote, the BBS respects the pre-formatted whitespace. The only other thing I forgot to mention is that I normally check the box to “Disable Smilies in this post” because I often have text in my scripts that gets converted by the BBS otherwise.

Jon

I’m using v2.71 of your app, and the Script Editor says 2.0 (v43) with AppleScript 1.9.3 under it. I’ve tried your app in both Firefox and Camino but can’t try in Safari because it’s broken (fails to start, just noticed it).

I copied & pasted the script into Script Editor (the applescript URL opened a new blank script window in Script Editor, but didn’t populate it with the script), compiled it, then converted it to BBCode (placed on the clipboard). Same versions of CStMC, Script Editor & AppleScript as Nova Scotian.


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

I discovered the problem applescript was writing to the .txt file as an rtf I fixed it by writing as string