Re: How can I make this get the user ID of the user dropping the files?
Re: How can I make this get the user ID of the user dropping the files?
- Subject: Re: How can I make this get the user ID of the user dropping the files?
- From: Graff <email@hidden>
- Date: Tue, 01 Jun 2004 19:25:11 -0400
See if this works. I changed the script around a bit because there was
no need to call the "do shell script" command. Everything you are
doing in this script can be done using plain-vanilla AppleScript 1.9:
----
on adding folder items to this_folder after receiving these_items
set myPrefixString to "gtx_"
tell application "Finder"
if ((name of item 1 of these_items) starts with myPrefixString) then
else
set myUserName to owner of item 1 of these_items
set myGroup to group of item 1 of these_items
set myFolderName to (myPrefixString & myUserName)
set myGenerationCount to 0
repeat while (exists folder myFolderName of this_folder)
set myGenerationCount to myGenerationCount + 1
set myFolderName to (myPrefixString & myUserName &
myGenerationCount)
end repeat
set theProps to {name:myFolderName, owner:myUserName,
group:"admin", owner privileges:read write, group privileges:read only,
everyones privileges:none}
set newFolder to make new folder at this_folder with properties
theProps
move these_items to newFolder
end if
end tell
end adding folder items to
----
Mind the line wrapping, there are some long lines in there. If you
have a problem with them then e-mail me directly and I'll send you the
script as an attachment.
I'm getting the user name directly from the information on transferred
file, since I figure that will be the best way to determine who it
belongs to.
- Ken
On Jun 1, 2004, at 2:07 PM, Bruce Carter wrote:
Greetings all,
A while ago, I needed a script to grab up all of the files that a user
dropped as a bunch onto a folder on a server, put them in a folder of
their own, and name it with the user's ID. I came up with the
following, which almost works:
on adding folder items to this_folder after receiving these_items
-- set up flags so the routine doesn't recurse itself to death when
the enclosing folder is created
set myPrefixString to "gtx_"
set myPrefixLength to length of myPrefixString
-- check the first item to see if it is a folder we made
set myCheckPath to (item 1 of these_items) as string
--display dialog "myCheckPath is: " & myCheckPath
set mySavedTextItemDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set myCheckName to text item -2 of myCheckPath
set AppleScript's text item delimiters to mySavedTextItemDelimiters
--display dialog "myCheckName is: " & myCheckName
-- see if the beginning of the folder name is our prefix code
if text 1 through myPrefixLength of myCheckName is myPrefixString then
-- if this is a folder that we created as part of this process, if
so, terminate
--display dialog "Stopped self-initiated add handling"
else
-- if not, process the items
-- show what folder we are in
--display dialog "Current folder is: " & (this_folder as string)
-- get the short user name from the shell
set myUserName to do shell script "whoami"
-- show the short user name
--display dialog "User name is: " & myUserName
-- set up the folder to have the same name as the user
set myFolderName to (myPrefixString & myUserName)
-- display dialog "Proposed folder name is: " & myFolderName
tell application "Finder"
-- check to see if the folder name is unique, if not append a
counter
set myGenerationCount to 0
repeat while (exists folder myFolderName of this_folder)
--display dialog (myFolderName as string) & " exists, incrementing
generation count."
set myGenerationCount to myGenerationCount + 1
set myFolderName to (myPrefixString & myUserName &
myGenerationCount)
end repeat
-- got a good folder name
-- display dialog "Selected folder name is: " & myFolderName
-- make the folder and set the permissions
make new folder at this_folder with properties {name:myFolderName}
set myUnixCompatibleFolderName to the quoted form of the POSIX path
of ((this_folder as string) & myFolderName)
-- display dialog "Quoted folder path is: " &
myUnixCompatibleFolderName
do shell script "chown :admin " & myUnixCompatibleFolderName
do shell script "chmod 750 " & myUnixCompatibleFolderName
-- move the dropped items into the folder
repeat with i from 1 to number of items in these_items
set myFilePath to (item i of these_items as text)
-- display dialog "myFilePath is: " & myFilePath
set myUnixCompatibleFileName to the quoted form of the POSIX path
of (myFilePath as string)
-- display dialog "Quoted file path is: " &
myUnixCompatibleFileName
do shell script "mv " & myUnixCompatibleFileName & " " &
myUnixCompatibleFolderName
end repeat
end tell
end if
end adding folder items to
The problem is, as you may have already figured out, that this gets
the user ID of the person signed on to the server console, not the ID
of the person who dropped the files. Anyone know of a way to fix
that, or a better way to do this? I can't just put a script on the
client machines because there are Windows clients that need to have
this work too.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.