How can I make this get the user ID of the user dropping the files?
How can I make this get the user ID of the user dropping the files?
- Subject: How can I make this get the user ID of the user dropping the files?
- From: Bruce Carter <email@hidden>
- Date: Tue, 1 Jun 2004 13:07:49 -0500
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.
--
Bruce Carter, ACTC, MacCSE, MCP
http://www.nd.edu/~bcarter/
Senior Systems Engineer
mailto:email@hidden
Riley Hall of Art, Room 217 AIM:bcarteratnd
University of Notre Dame +1 574 631 2967 Voice
Notre Dame, IN 46556-0539 +1 574 631 8201 FAX
_______________________________________________
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.