Re: Invisible File Generator V1
Re: Invisible File Generator V1
- Subject: Re: Invisible File Generator V1
- From: Nigel Garvey <email@hidden>
- Date: Sun, 03 Mar 2019 09:55:30 +0000
Gil Dawson wrote on Sat, 02 Mar 2019 18:36:12 -0800:
>Hi--
>
>I recoded my "invisible file generator" to eliminate the POSIX stuff and
>set it up so that it might work on your machine:
>
>set QIFnListsFolder to path to desktop
>
>set QifFileName to "Invisible File Issue"
>
>set TxtFilePath to (QIFnListsFolder & QifFileName & ".txt") as text
>
>try
> close access file TxtFilePath
>end try
>open for access file TxtFilePath with write permission
>write "Test Line" & return to file TxtFilePath starting at eof as text
>close access file TxtFilePath
It works OK on my 10.11.6 machine.
>(I thought it odd I had to add "as text". The error message showed a
list
>of three strings.)
'path to desktop' returns an alias. Concatenating the text QifFileName
to that produces a list containing an alias and a text. Concatenating
".txt" to that list produces another list containing the alias and the
two texts. Your added 'as text' coerces the last list to text using the
current setting of AppleScript's text item delimiters. (It's conceivable
that if the TIDs were "." at the time of the coercion, the file would be
created with the name ".Invisible File Issue..txt", which would render
it invisible. But then you wouldn't have been able to find it with your
other checks.)
It's safer and more efficient to coerce the alias to text first so that
the concatenations are of text to text throughout:
set TxtFilePath to (QIFnListsFolder as text) & QifFileName & ".txt"
>try
> close access file TxtFilePath
>end try
>open for access file TxtFilePath with write permission
>write "Test Line" & return to file TxtFilePath starting at eof as text
>close access file TxtFilePath
Use the reference number returned by 'open for access' and use a 'try'
statement to ensure that, in the unlikely event of an error occurring
while the file's open, the script keeps going long enough to close it:
set fRef to (open for access file TxtFilePath with write permission)
try
write "Test Line" & return to fRef starting at eof as text
close access fRef
on error errMsg
close access fRef
display dialog errMsg
end try
Bob Stern wrote on Sun, 03 Mar 2019 00:48:30 -0800:
>set QIFnListsFolder to (path to desktop) as text
Actually, 'path to' has an 'as' parameter which can return text
directly, which is very slightly more efficient:
set QIFnListsFolder to (path to desktop as text) -- 'path to' returns the
path as text.
set QIFnListsFolder to (path to desktop) as text -- 'path to' returns an
alias, which AppleScript then coerces to text.
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden