• 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
Permissions problem with script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Permissions problem with script


  • Subject: Permissions problem with script
  • From: Paul Thompson <email@hidden>
  • Date: Wed, 25 Jan 2006 10:30:11 -0500

  Hi everyone,

I have been working with a fellow applescripter who has been helping me out immensely with a script that I've been trying to get working. It is designed to replace the username and password in the / etc/cups/printers.conf for authenticated windows printers. After I compile it and try to run it, I receive a Network File Permission error. It occurs right near the end of the script. He has suggested that I post the script to the list to see if anyone might have an idea on how to fix it. I have included the script below, but I just wanted to say thank you to Mark for all the help he has given me.


-- startup disks have different names so.... tell application "Finder" to set startupdisk to name of startup disk

-- copies original printers.conf to tmp folder for modification
do shell script ("cp /etc/cups/printers.conf /tmp/printers.conf") with administrator privileges


-- reads original printers.conf to theText variable
set theText to do shell script ("cat /tmp/printers.conf") with administrator privileges


-- set printersconf variable to path to tempfile as string
set printersconf to "/tmp/printers.conf"
set printersconf to (POSIX file printersconf) as string

-- set username and userpass to variables
set username to text returned of (display dialog "Enter your User Name:" default answer "your username")
set userpass to text returned of (display dialog "Enter your password:" default answer "your password")


-- replace text in variable theText to unsername and pass
set tempdelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to "username"
set temptext to every text item of theText as list
set AppleScript's text item delimiters to username
set temptext to every item of temptext as string
set AppleScript's text item delimiters to "userpass"
set temptext to every text item of temptext as list
set AppleScript's text item delimiters to userpass
set theText to every item of temptext as string

-- safely convert to unicode special chars
set theText to the theText as Unicode text

-- this is a handler it calls the writefile below with theText variable and printersconf variable
writeFile(theText, printersconf)


-- this copies the tmp file back to the /etc/cups folder
do shell script ("cp /tmp/printers.conf /etc/cups/printers.conf") with administrator privileges


-- set permissions back on the file
do shell script ("chown root:lp /etc/cups/printers.conf") with administrator privileges


-- restart cups .... not sure you need this but it couldnt hurt
do shell script ("killall -HUP cupsd") with administrator privileges


--- this handler writes the file called earlier these are an easy way to reuse code it can be called multiple times but only needs to be written once...
on writeFile(thecontents, thefile)
set f to (open for access (thefile) as alias with write permission) -- edited
write thecontents to f
close access f
end writeFile


The error is in the line "open for access (thefile) as alias with write permission"

  Thank you in advance,

  Paul
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Permissions problem with script
      • From: "Mark J. Reed" <email@hidden>
    • Re: Permissions problem with script
      • From: "Mark J. Reed" <email@hidden>
  • Prev by Date: Re: Url link
  • Next by Date: Re: Permissions problem with script
  • Previous by thread: Re: Moving events between calendars in iCal
  • Next by thread: Re: Permissions problem with script
  • Index(es):
    • Date
    • Thread