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

Re: Permissions problem with script


  • Subject: Re: Permissions problem with script
  • From: Paul Thompson <email@hidden>
  • Date: Mon, 30 Jan 2006 13:09:27 -0500

  Hi Mark,

Thank you for all of your help. I made the changes you suggested and it is almost working. I have included a paste of the new script below:

-- reads original printers.conf to theText variable
set theText to do shell script ("cat /etc/cups/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 username 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 creates a backup of the /etc/cups/printer.conf file
do shell script ("cp /etc/cups/printers.conf /etc/cups/ printers.conf.pre-userpass") with administrator privileges


-- 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) with write permission) -- edited
write thecontents to f
close access f
end writeFile


When I run the script, it executes as it should, but the file that gets written, when you do a get info on it, is listed as a Text Document which text edit can open, while on another machine the original printers.conf file is listed as a Document which can be opened through the terminal. Any Idea how I would reset the file so that it would be a unix file

  Thank you,

  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>
References: 
 >Permissions problem with script (From: Paul Thompson <email@hidden>)
 >Re: Permissions problem with script (From: "Mark J. Reed" <email@hidden>)

  • Prev by Date: ANNOUNCE: FaceSpan 4.3
  • Next by Date: Where can I get more info?
  • Previous by thread: Re: Permissions problem with script
  • Next by thread: Re: Permissions problem with script
  • Index(es):
    • Date
    • Thread