Newbie seeks help writing text files to Mac OS X
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Newbie seeks help writing text files to Mac OS X
Hello all...my first post to a LiveCode forum. I have developed a little app that reads in one big text file, replaces unwanted text and formatting, and then writes out a set of smaller, cleaner text files. It works perfectly in source, merrily reading and writing files to its heart's content. Yesterday was the first time I built a standalone. Never writes a file.
I looked around the forums and found some semi-guidance for somewhat similar situations, but every combination of settings on the Mac tab failed to change anything. I feel like I must be missing something in the PLIST and/or build settings.
For what it is worth, I am running OS X (10.10.5) on a MacBook Pro. Does anyone know of common causes for me to start looking at first?
Thanks,
Bill
I looked around the forums and found some semi-guidance for somewhat similar situations, but every combination of settings on the Mac tab failed to change anything. I feel like I must be missing something in the PLIST and/or build settings.
For what it is worth, I am running OS X (10.10.5) on a MacBook Pro. Does anyone know of common causes for me to start looking at first?
Thanks,
Bill
-
- VIP Livecode Opensource Backer
- Posts: 9838
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Newbie seeks help writing text files to Mac OS X
Welcome aboard!Bill Rose wrote:Hello all...my first post to a LiveCode forum.
When you encounter an issue with a specific part of your code it's often helpful to include the code in your post so we can offer suggestions. For now, in the absence of the code, I can at least guess about how we might be able to diagnose this.I have developed a little app that reads in one big text file, replaces unwanted text and formatting, and then writes out a set of smaller, cleaner text files. It works perfectly in source, merrily reading and writing files to its heart's content. Yesterday was the first time I built a standalone. Never writes a file.
There are two frequently-used ways to write a file, "put <data>" into url..." and "open file..."/"write <data> to file..."/"close file...". Each uses slightly different routines internally, but both have one thing in common: you can check "the result" immediately after the presumed point of failure to see if the engine is providing error info for you. Additionally, if it is you can also include a call to the sysError() function to find out what error code the OS may be returning to provide more specifics.
For example, if you're using the "url" form, you can check "the result" like this:
Code: Select all
put tData into url ("binfile:"& tFilePath)
if the result is not empty then
answer the result &" ("&sysError() &")"
exit to top
end if
If the case was an invalid path, the answer dialog may include something like this:
"can't open file (2)"
Please let us know what you find. In most cases we see either invalid paths or inappropriate write permissions, and hopefully what you're encountering will be as easily solvable.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Newbie seeks help writing text files to Mac OS X
OK, I did get a "can't create that directory (17)" error message back when attempting to create my folder:
As for the text file write outs, I use the open/write/close methods:
Bill
Code: Select all
global gMyFilePath1
on mouseUp
set the defaultFolder to specialFolderPath("resources")
put defaultFolder & "/" & "Files to Verify" into gMyFilePath1
create folder gMyFilePath1
if the result is not empty then
answer the result &" ("&sysError() &")"
exit to top
end if
end mouseUp
Code: Select all
open file gMyFilePath1 & "/"& (item i of gTextFileNamesList)&".txt" for write
write gSelectedPortion to file gMyFilePath1 & "/"& (item i of gTextFileNamesList)&".txt"
close file gMyFilePath1 & "/"& (item i of gTextFileNamesList)&".txt"
-
- Livecode Opensource Backer
- Posts: 9388
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Newbie seeks help writing text files to Mac OS X
I use a rather simpler way of doing things:
on mouseUp
ask file "Choose where you wish to export your text"
if the result = "cancel"
then exit mouseUp
else
put the Text of fld "fStuffToExport" into url("file:" & it & ".txt")
get the longFilePath of it
set the itemDelimiter to slash
set the defaultFolder to item 1 to -2 of the longFilePath of it
end if
end mouseUp
Give it a try; you never know.
on mouseUp
ask file "Choose where you wish to export your text"
if the result = "cancel"
then exit mouseUp
else
put the Text of fld "fStuffToExport" into url("file:" & it & ".txt")
get the longFilePath of it
set the itemDelimiter to slash
set the defaultFolder to item 1 to -2 of the longFilePath of it
end if
end mouseUp
Give it a try; you never know.
-
- VIP Livecode Opensource Backer
- Posts: 9838
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Newbie seeks help writing text files to Mac OS X
Thanks, Bill. I'm having a tough time searching Google to find out what error 17 means on Mac. Can you share the full path you're attempting to write to?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Newbie seeks help writing text files to Mac OS X
Hi,
you tried another folder but "resources" already?
Maybe "temporary", "home" or "documents"?
Have fun!
you tried another folder but "resources" already?
Maybe "temporary", "home" or "documents"?
Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
Re: Newbie seeks help writing text files to Mac OS X
Richard,
I was having the same problem trying to find error 17. These are the two paths I am trying to write to:
/Users/bmr1/Desktop/LiveCode Jeopardy Engine/Files to Verify
/Users/bmr1/Desktop/LiveCode Jeopardy Engine/Array Files
Bill
I was having the same problem trying to find error 17. These are the two paths I am trying to write to:
/Users/bmr1/Desktop/LiveCode Jeopardy Engine/Files to Verify
/Users/bmr1/Desktop/LiveCode Jeopardy Engine/Array Files
Bill
Re: Newbie seeks help writing text files to Mac OS X
Hi Bill,
1. welcome to the forum!
2.
In a standalone this folder is inside of the MacOS APP packed and a "normal" user does not have WRITE permissions here,
that's why you get hte above mentioned error!
if you need to store any app data on a Mac use either:
-> specialfolderpath("documents")
or maybe:
-> specialfolderpath("preferences")
Check the dictionary for more (and platform specific) specialfolderpath names.
Avoid setting the defaultfolder if you can have an bulletproof absolute pathname
AND ALWAYS do some errorchecking!
Yes, it's tedious, but neccessary!
Get used to put parens when concatenating object and file names to avoid surpises from the engine!
Or save some typing by putting the filepath into a variable first
If you deal with smallish (maybe max 20 MB) data, you can use the shorter URL syntax if you like
Best
Klaus
1. welcome to the forum!
2.
OK, I did get a "can't create that directory (17)" error message back when attempting to create my folder:
Code: Select all
global gMyFilePath1
on mouseUp
set the defaultFolder to specialFolderPath("resources")
...
that's why you get hte above mentioned error!
if you need to store any app data on a Mac use either:
-> specialfolderpath("documents")
or maybe:
-> specialfolderpath("preferences")
Check the dictionary for more (and platform specific) specialfolderpath names.
Code: Select all
...
set the defaultFolder to specialFolderPath("resources")
put defaultFolder & "/" & "Files to Verify" into gMyFilePath1
create folder gMyFilePath1
...
AND ALWAYS do some errorchecking!
Yes, it's tedious, but neccessary!
Code: Select all
...
put specialFolderPath("resources") & "/Files to Verify" into gMyFilePath1
if there is not a folder gMyFilePath1 then
create folder gMyFilePath1
end if
...
Code: Select all
...
open file (gMyFilePath1 & "/"& (item i of gTextFileNamesList)&".txt") for write
write gSelectedPortion to file (gMyFilePath1 & "/"& (item i of gTextFileNamesList)&".txt")
close file (gMyFilePath1 & "/"& (item i of gTextFileNamesList)&".txt")
...
Code: Select all
...
put gMyFilePath1 & "/"& (item i of gTextFileNamesList)&".txt" into tTargetFile
open file tTargetFile for write
write gSelectedPortion to file tTargetFile
close file tTargetFile
...
Code: Select all
...
put gSelectedPortion into URL("FILE:" & gMyFilePath1 & "/"& (item i of gTextFileNamesList)&".txt")
## Supposed the content of gSelectedPortion is TEXT, if it is binary stuff, use BINFILE
...
Best
Klaus
Re: Newbie seeks help writing text files to Mac OS X
Klaus,
Bingo! The problem was indeed my pointing to the resources path, which also further explains the odd behavior of it working fine prior to packing it up, but never again afterwards. Lesson learned.
I ditched the default Folder setting I was doing and went with this:
I am just too green , but it is coming. I will implement your other tips also. Many thanks Klaus, Richard, and others.
Bingo! The problem was indeed my pointing to the resources path, which also further explains the odd behavior of it working fine prior to packing it up, but never again afterwards. Lesson learned.
I ditched the default Folder setting I was doing and went with this:
Code: Select all
put specialFolderPath("documents") & "/" & "Files to Verify" into gMyFilePath1