• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: getting a a hidden file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getting a a hidden file


  • Subject: Re: getting a a hidden file
  • From: Christopher Stone <email@hidden>
  • Date: Sat, 30 Oct 2010 02:02:46 -0500

On Oct 29, 2010, at 16:10, Jason Lantz wrote:
I'm a pretty new applescript user so I apologize if this is an obvious question.

I need to "get" a hidden file, but I really don't want to go through the process of showing all files and restarting Finder.  I also need the script to be usable on multiple computers.  This is the statement I initially tried, but it isn't able to find the hidden file.
______________________________________________________________________

Hey Jason,

Some bits for you to chew on.  I think they're reasonably self-documenting, but holler at me if you don't get something.  As long as you're writing and reading the file you're in complete control of it, and the user need do nothing.

--
Chris


# ======================================================================
on test_file_exists(targetFilePath)
try
(POSIX file targetFilePath) as alias ## Generates an error if no file exists ##
on error errMsg number errNum
set errorText to "Script Failed in test_file_exists handler..." & linefeed & linefeed ¬
& errMsg & linefeed & linefeed & "Error Number: " & errNum
error errorText
end try
end test_file_exists
# ======================================================================
on read_config_file(targetFilePath)
try
set fileData to read targetFilePath
return fileData
on error errMsg number errNum
set errorText to "Script Failed in read_config_file handler..." & linefeed & linefeed ¬
& errMsg & linefeed & linefeed & "Error Number: " & errNum
error errorText
end try
end read_config_file
# ======================================================================
on write_to_config_file(textToWrite, targetFilePath)
try
set resultNumber to open for access targetFilePath ¬
with write permission
set eof of resultNumber to 0
write textToWrite to resultNumber
close access resultNumber
on error errMsg number errNum
try
close access resultNumber
on error errMsg number errNum
set errorText to "Script Failed in write_to_config_file handler..." & linefeed & linefeed ¬
& errMsg & linefeed & linefeed & "Error Number: " & errNum
error errorText
end try
end try
end write_to_config_file
# ======================================================================

property targetFilePath : POSIX path of (path to application support folder from user domain) & ¬
".yourConfigFileName"
property LF : linefeed

# ======================================================================

# Write the file first to make sure it gets created.
# Overwrites if file already exists.
try
set textToWrite to "Don't you know that none are blind 
To the lie, and you think I don't find what you hide?"
set writeResult to write_to_config_file(textToWrite, targetFilePath) of me
# Do something else.
on error errMsg number errNum
beep
tell me to display dialog "Error: " & errMsg
end try

# Test for existence of the '.yourConfigFileName' file.
try
test_file_exists(targetFilePath) of me ## stops executing here if no file ##
## If file exists then code here gets executed ##
on error errMsg number errNum
beep
tell me to display dialog "Error: " & errMsg
end try

# Read the file.
try
set configData to read_config_file(targetFilePath) of me
on error errMsg number errNum
beep
tell me to display dialog "Error: " & errMsg
end try

tell application "TextEdit"
activate
open targetFilePath
end tell

 _______________________________________________
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

References: 
 >getting a a hidden file (From: Jason Lantz <email@hidden>)

  • Prev by Date: Re: getting a a hidden file
  • Next by Date: A newbie's problems with Pages and Applescript
  • Previous by thread: Re: getting a a hidden file
  • Next by thread: A newbie's problems with Pages and Applescript
  • Index(es):
    • Date
    • Thread