Welcome to MacForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Applescript to fix permissions on imported files

 
   Macintosh computer (Home) -> Apple Scripts RSS
Next:  Bluetooth/wireless mouse and keyboard on the Wind..  
Author Message
Pedro

External


Since: Feb 13, 2007
Posts: 3



(Msg. 1) Posted: Sun Aug 24, 2008 5:14 pm
Post subject: Applescript to fix permissions on imported files
Archived from groups: alt>comp>lang>applescript (more info?)

Hi people

Please forgive me asking for someone else, but 'someone else' reckons
they won't understand the answer, so ...

My friend has just bought a MacBook Pro and tried to used the
'importing old files' utility to get the files from her old G4 PPC -
via Firewire, I think.

The files are there in the laptop, but she has to log out and change
user to access them. Not handy!

Is there an applescript that will change all the ownerships so she can
open them in the normal way?

I found this applescript:

to chOwn(aliasToFolder)
set mypath to quoted form of POSIX path of aliasToFolder
set uName to do shell script "whoami"
do shell script "chown -R" & uName & space & mypath & ";chmod 775 "
& mypath with administrator privileges
end chOwn

which was quoted on:

http://lists.apple.com/archives/applescript-users/2006/Aug/msg00255.html

Will this do the trick? and if so ...

1) Am I right she should edit this and replace "uName" with her login
username (it's a single user Mac so she is also Admin)

2) Does she also have to replace "path" with something more specific,
and if so, then what? [Sorry I'm vague on that path thing!]

3) Does this script (if appropriate) do the job by running, or should
she drag-drop the folder with the files onto the script-app icon?

Apologies if this isn't clear. I did my best!

Most grateful for any advice

TIA

Pedro

 >> Stay informed about: Applescript to fix permissions on imported files 
Back to top
Login to vote
Jerry Kindall

External


Since: Jul 09, 2003
Posts: 560



(Msg. 2) Posted: Sun Aug 24, 2008 5:14 pm
Post subject: Re: Applescript to fix permissions on imported files [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article , Pedro
wrote:

> Hi people
>
> Please forgive me asking for someone else, but 'someone else' reckons
> they won't understand the answer, so ...
>
> My friend has just bought a MacBook Pro and tried to used the
> 'importing old files' utility to get the files from her old G4 PPC -
> via Firewire, I think.
>
> The files are there in the laptop, but she has to log out and change
> user to access them. Not handy!
>
> Is there an applescript that will change all the ownerships so she can
> open them in the normal way?
>
> I found this applescript:
>
> to chOwn(aliasToFolder)
> set mypath to quoted form of POSIX path of aliasToFolder
> set uName to do shell script "whoami"
> do shell script "chown -R" & uName & space & mypath & ";chmod 775 "
> & mypath with administrator privileges
> end chOwn
>
> which was quoted on:
>
> http://lists.apple.com/archives/applescript-users/2006/Aug/msg00255.html
>
> Will this do the trick? and if so ...

Well, it looks like it should do the trick of changing the owner of a
file to the current user. However, you will still need to write the
rest of the script -- the part that gathers the files that need their
owners changed, in whatever way you like, and passes them to this
handler.

> 1) Am I right she should edit this and replace "uName" with her login
> username (it's a single user Mac so she is also Admin)

The script uses the UNIX command whoami to figure out the username of
the current user, and sets the owner to that user. If you want to use
a different user than the current user, you could hard-code the name
instead of using whoami, or ask them to enter a user, etc.

> 2) Does she also have to replace "path" with something more specific,
> and if so, then what? [Sorry I'm vague on that path thing!]

No, the path is obtained from the alias passed in to the handler as a
variable. You just pass in an alias to the file you want to change.

> 3) Does this script (if appropriate) do the job by running, or should
> she drag-drop the folder with the files onto the script-app icon?

It works either way -- whichever way you write the rest of the script.
You could hard-code a list of files to have their owner changed, use an
Open dialog to select one or several, or accept files dragged onto the
icon -- however you want to do it. You just write the code to make it
work that way.

Is there any particular reason you want to do this with an AppleScript?
It seems the long way around. You can just open Terminal and do:

sudo chown -R `whoami` /Path/To/Folder

(You don't have to type the path to the folder; simply drag the folder
from the Finder into the Terminal window at this point in the command.)

After prompting for the administrator's password, this command will
change the owner of all the files in the specified folder to the
current user.

--
Jerry Kindall, Seattle, WA <http://www.jerrykindall.com/>

Send only plain text messages under 32K to the Reply-To address.
This mailbox is filtered aggressively to thwart spam and viruses.

 >> Stay informed about: Applescript to fix permissions on imported files 
Back to top
Login to vote
John Stewart

External


Since: Jul 26, 2008
Posts: 2



(Msg. 3) Posted: Mon Aug 25, 2008 9:38 am
Post subject: Re: Applescript to fix permissions on imported files [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On 2008-08-24 13:14:06 -0400, Pedro said:

> Hi people
>
> Please forgive me asking for someone else, but 'someone else' reckons
> they won't understand the answer, so ...
>
> My friend has just bought a MacBook Pro and tried to used the
> 'importing old files' utility to get the files from her old G4 PPC -
> via Firewire, I think.
>
> The files are there in the laptop, but she has to log out and change
> user to access them. Not handy!
>
> Is there an applescript that will change all the ownerships so she can
> open them in the normal way?
>
> I found this applescript:
>
> to chOwn(aliasToFolder)
> set mypath to quoted form of POSIX path of aliasToFolder
> set uName to do shell script "whoami"
> do shell script "chown -R" & uName & space & mypath & ";chmod 775 "
> & mypath with administrator privileges
> end chOwn
>
> which was quoted on:
>
> http://lists.apple.com/archives/applescript-users/2006/Aug/msg00255.html
>
> Will this do the trick? and if so ...

not as written

>
> 1) Am I right she should edit this and replace "uName" with her login
> username (it's a single user Mac so she is also Admin)

no, the script already takes care of it.

>
> 2) Does she also have to replace "path" with something more specific,
> and if so, then what? [Sorry I'm vague on that path thing!]

It's what is called a handler (subroutine) and isn't a complete script.
As written the path should be set within the script at some point.

> 3) Does this script (if appropriate) do the job by running, or should
> she drag-drop the folder with the files onto the script-app icon?

As shown it doesn't do either but since this isn't a complete script
either could be possible.

Here is an alternative (almost identical) script that can be saved
either as an application or compiled script in the System Script menu.
I prefer the latter. It is not a drag and drop script.

--> Cut <--
set uName to short user name of (system info)
set targ to quoted form of POSIX path of (choose folder with prompt
"choose a folder" without multiple selections allowed)

do shell script "chown -R " & uName & space & targ & ";chmod -R 775 " &
targ with administrator privileges
--> Cut <--


Some of the lines in this are wrapped due to length.Please remove
wrapping prior to use.

J
 >> Stay informed about: Applescript to fix permissions on imported files 
Back to top
Login to vote
Pedro

External


Since: Feb 13, 2007
Posts: 3



(Msg. 4) Posted: Mon Aug 25, 2008 2:25 pm
Post subject: Re: Applescript to fix permissions on imported files [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article , Jerry
Kindall wrote:

> In article , Pedro
> wrote:
>
> > Hi people
> >
> > Please forgive me asking for someone else, but 'someone else' reckons
> > they won't understand the answer, so ...
> >
> > My friend has just bought a MacBook Pro and tried to used the
> > 'importing old files' utility to get the files from her old G4 PPC -
> > via Firewire, I think.
> >
> > The files are there in the laptop, but she has to log out and change
> > user to access them. Not handy!
> >
> > Is there an applescript that will change all the ownerships so she can
> > open them in the normal way?
> >
> > I found this applescript:
> >
> > to chOwn(aliasToFolder)
> > set mypath to quoted form of POSIX path of aliasToFolder
> > set uName to do shell script "whoami"
> > do shell script "chown -R" & uName & space & mypath & ";chmod 775 "
> > & mypath with administrator privileges
> > end chOwn
> >
> > which was quoted on:
> >
> > http://lists.apple.com/archives/applescript-users/2006/Aug/msg00255.html
> >
> > Will this do the trick? and if so ...
>
> Well, it looks like it should do the trick of changing the owner of a
> file to the current user. However, you will still need to write the
> rest of the script -- the part that gathers the files that need their
> owners changed, in whatever way you like, and passes them to this
> handler.
>
> > 1) Am I right she should edit this and replace "uName" with her login
> > username (it's a single user Mac so she is also Admin)
>
> The script uses the UNIX command whoami to figure out the username of
> the current user, and sets the owner to that user. If you want to use
> a different user than the current user, you could hard-code the name
> instead of using whoami, or ask them to enter a user, etc.
>
> > 2) Does she also have to replace "path" with something more specific,
> > and if so, then what? [Sorry I'm vague on that path thing!]
>
> No, the path is obtained from the alias passed in to the handler as a
> variable. You just pass in an alias to the file you want to change.
>
> > 3) Does this script (if appropriate) do the job by running, or should
> > she drag-drop the folder with the files onto the script-app icon?
>
> It works either way -- whichever way you write the rest of the script.
> You could hard-code a list of files to have their owner changed, use an
> Open dialog to select one or several, or accept files dragged onto the
> icon -- however you want to do it. You just write the code to make it
> work that way.
>
> Is there any particular reason you want to do this with an AppleScript?
> It seems the long way around. You can just open Terminal and do:
>
> sudo chown -R `whoami` /Path/To/Folder
>
> (You don't have to type the path to the folder; simply drag the folder
> from the Finder into the Terminal window at this point in the command.)
>
> After prompting for the administrator's password, this command will
> change the owner of all the files in the specified folder to the
> current user.

Thanks, Jerry, for this helpful answer. I have in the past taught my
friend to use a few Unix tools in the Terminal, so she may be game for
this. Being a MacOS user from pre-BSD days, I suppose my thoughts went
to Applescript first, but as you say, it's not essential for this task,
and it's great to have a choice of approaches.

Thanks again

Pedro
 >> Stay informed about: Applescript to fix permissions on imported files 
Back to top
Login to vote
Pedro

External


Since: Feb 13, 2007
Posts: 3



(Msg. 5) Posted: Mon Aug 25, 2008 2:27 pm
Post subject: Re: Applescript to fix permissions on imported files [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article , John Stewart
wrote:

> On 2008-08-24 13:14:06 -0400, Pedro said:
>
> > Hi people
> >
> > Please forgive me asking for someone else, but 'someone else' reckons
> > they won't understand the answer, so ...
> >
> > My friend has just bought a MacBook Pro and tried to used the
> > 'importing old files' utility to get the files from her old G4 PPC -
> > via Firewire, I think.
> >
> > The files are there in the laptop, but she has to log out and change
> > user to access them. Not handy!
> >
> > Is there an applescript that will change all the ownerships so she can
> > open them in the normal way?
> >
> > I found this applescript:
> >
> > to chOwn(aliasToFolder)
> > set mypath to quoted form of POSIX path of aliasToFolder
> > set uName to do shell script "whoami"
> > do shell script "chown -R" & uName & space & mypath & ";chmod 775 "
> > & mypath with administrator privileges
> > end chOwn
> >
> > which was quoted on:
> >
> > http://lists.apple.com/archives/applescript-users/2006/Aug/msg00255.html
> >
> > Will this do the trick? and if so ...
>
> not as written
>
> >
> > 1) Am I right she should edit this and replace "uName" with her login
> > username (it's a single user Mac so she is also Admin)
>
> no, the script already takes care of it.
>
> >
> > 2) Does she also have to replace "path" with something more specific,
> > and if so, then what? [Sorry I'm vague on that path thing!]
>
> It's what is called a handler (subroutine) and isn't a complete script.
> As written the path should be set within the script at some point.
>
> > 3) Does this script (if appropriate) do the job by running, or should
> > she drag-drop the folder with the files onto the script-app icon?
>
> As shown it doesn't do either but since this isn't a complete script
> either could be possible.
>
> Here is an alternative (almost identical) script that can be saved
> either as an application or compiled script in the System Script menu.
> I prefer the latter. It is not a drag and drop script.
>
> --> Cut <--
> set uName to short user name of (system info)
> set targ to quoted form of POSIX path of (choose folder with prompt
> "choose a folder" without multiple selections allowed)
>
> do shell script "chown -R " & uName & space & targ & ";chmod -R 775 " &
> targ with administrator privileges
> --> Cut <--
>
>
> Some of the lines in this are wrapped due to length.Please remove
> wrapping prior to use.
>
> J
>

Thanks John for your help. Along with Jerry's shell script I now have
two ways of doing this, and I'll let my friend make the choice.

I'm grateful for your time and kindness.

Pedro
 >> Stay informed about: Applescript to fix permissions on imported files 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
New to Applescript - Hello, I'm brand new to Applescript - I've done a lot with VBS but never touched Applescript. Are there some good script repositories online? AppleScript Editors? Manuals? Any help will be greatly appreciated!!! TIA, Bill bill@2burkes.com

Applescript RSS - Is there any way to acquire an RSS feed using Applescript? I'd like to be able to specify the RSS URL, then have Applescript consume the most recent 5 entries. Thanks, A

Use applescript in Keynote - Am trying to use applescript to modify the color of a selected text element on a slide in Keynote. is it possible to have a script that can set the font, size, color of a selected text in keynote using applescript. The dictionary mentions about a..

AppleScript 2.2 (Lion) - Hello, Lion's AppleScript is version 2.2. Apple has yet to make the release notes available, but some new features are presented here: http://www.macosxautomation.com/lion/index.html Patrick -- Patrick Stadelmann <Patrick.Stadelmann@unine.ch>

Leopard, Firefox & Applescript - Can anyone tell me why a script I wrote to log in to my bank no longer works in Firefox since I installed Leopard? Can it by fixed? Thanks
   Macintosh computer (Home) -> Apple Scripts All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]