Change of Username (Prompt end user for name)

simon_brooke
New Contributor III

Hi All,

I have around 500 mac's where at least half get passed around in departments. I have an extension attribute to tell me the last user.

I have to export this to a CSV with the current username assigned (Active Directory).

Does anyone have a script that will prompt the user to type in their username and select their department from my current list of departments (Not Assigned from AD).

Many thanks in Advance
Simon

2 REPLIES 2

Hugonaut
Valued Contributor II

this is an applescript i was building but never actually utilized, it does what you want though, it's kinda rough around the edges. again, i never put this into production - if you run from jamf, shouldnt need to set user & pass inside the script, if you do, make sure to encrypt the credentials.

#!/usr/bin/osascript 

-- Set Ad Privvies
set UNAME to "admin"
set PASSW to "pass"

set stafffirstname to text returned of (display dialog "Please type your first name." default answer "")
set stafflastname to text returned of (display dialog "Please type your Last name." default answer "")
set stafffullname to stafffirstname & " " & stafflastname

(*  █████████████████████████████████████████████████████████████████████████████████████████████
Departments
    --
    Department List Key- (Item 1:Admin) (Item 2:English) (Item 3:Enrollment & Support) (Item 4:Math) (Item 5:Science) (Item 6:School Services) 
    Department List Key- (Item 7:Social Studies) (Item 8:Specialty) (Item 9:Special Ed) (Item 10:Teaching Assistant) (Item 11:Technology) 
    *)

set DepartmentList to {"Admin", "English", "Enrollment & Support", "Math", "School Services", "Science", "Social Studies", "Specialty", "Special Ed.", "Technology"}

set Department to ¬
    (choose from list DepartmentList with prompt ¬
        "Choose Department" default items {item 1 of DepartmentList}) as text


(*  █████████████████████████████████████████████████████████████████████████████████████████████
    -- Departments ((Variables))
    --
    -- Sets Department Variables 
    *)

set Admin to Department is (item 1 of DepartmentList)

set English to Department is (item 2 of DepartmentList)

set Enrollment to Department is (item 3 of DepartmentList)

set Math to Department is (item 4 of DepartmentList)

set SchoolService to Department is (item 5 of DepartmentList)

set Science to Department is (item 6 of DepartmentList)

set SocialStudies to Department is (item 7 of DepartmentList)

set Specialty to Department is (item 8 of DepartmentList)

set SpecialEd to Department is (item 9 of DepartmentList)

set Technology to Department is (item 10 of DepartmentList)


(* █████████████████████████████████████████████████████████████████████████████████████████████
    Departments ((Assignment))
    --
     Assigns User to Admin Department
*)
try
    if Admin then do shell script "sudo /usr/local/jamf/bin/jamf recon -department Admin" user name UNAME password PASSW with administrator privileges
on error errMsg1 number errNum1
    display dialog "Error: " & errMsg1 & errNum1 with icon ":System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:Everyone.icns" as alias buttons {"Okay"}
end try

-- Assigns User to English Department
try
    if English then do shell script "sudo /usr/local/jamf/bin/jamf recon -department English" user name UNAME password PASSW with administrator privileges
on error errMsg2 number errNum2
    display dialog "Error: " & errMsg2 & errNum2 with icon ":System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:Everyone.icns" as alias buttons {"Okay"}
end try

-- Assigns User to Enrollment & Support Department
try
    if Enrollment then do shell script "sudo /usr/local/jamf/bin/jamf recon -department Enrollment_Support" user name UNAME password PASSW with administrator privileges
on error errMsg3 number errNum3
    display dialog "Error: " & errMsg3 & errNum3 with icon ":System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:Everyone.icns" as alias buttons {"Okay"}
end try

-- Assigns User to Math Department
try
    if Math then do shell script "sudo /usr/local/jamf/bin/jamf recon -department Math" user name UNAME password PASSW with administrator privileges
on error errMsg4 number errNum4
    display dialog "Error: " & errMsg4 & errNum4 with icon ":System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:Everyone.icns" as alias buttons {"Okay"}
end try

-- Assigns User to School_Services Department
try
    if SchoolService then do shell script "sudo /usr/local/jamf/bin/jamf recon -department School_Services" user name UNAME password PASSW with administrator privileges
on error errMsg5 number errNum5
    display dialog "Error: " & errMsg5 & errNum5 with icon ":System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:Everyone.icns" as alias buttons {"Okay"}
end try

-- Assigns User to Science Department
try
    if Science then do shell script "sudo /usr/local/jamf/bin/jamf recon -department Science" user name UNAME password PASSW with administrator privileges
on error errMsg6 number errNum6
    display dialog "Error: " & errMsg6 & errNum6 with icon ":System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:Everyone.icns" as alias buttons {"Okay"}
end try

-- Assigns User to Social Studies Department
try
    if SocialStudies then do shell script "sudo /usr/local/jamf/bin/jamf recon -department Social_Studies" user name UNAME password PASSW with administrator privileges
on error errMsg7 number errNum7
    display dialog "Error: " & errMsg7 & errNum7 with icon ":System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:Everyone.icns" as alias buttons {"Okay"}
end try

-- Assigns User to Special Ed Department
try
    if SpecialEd then do shell script "sudo /usr/local/jamf/bin/jamf recon -department Special_Ed" user name UNAME password PASSW with administrator privileges
on error errMsg8 number errNum8
    display dialog "Error: " & errMsg8 & errNum8 with icon ":System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:Everyone.icns" as alias buttons {"Okay"}
end try

-- Assigns User to Specialty Department
try
    if Specialty then do shell script "sudo /usr/local/jamf/bin/jamf recon -department Specialty" user name UNAME password PASSW with administrator privileges
on error errMsg9 number errNum9
    display dialog "Error: " & errMsg9 & errNum9 with icon ":System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:Everyone.icns" as alias buttons {"Okay"}
end try

-- Assigns User to Technology
try
    if Technology then do shell script "sudo /usr/local/jamf/bin/jamf recon -department Technology" user name UNAME password PASSW with administrator privileges
on error errMsg10 number errNum10
    display dialog "Error: " & errMsg10 & errNum10 with icon ":System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:Everyone.icns" as alias buttons {"Okay"}
end try


set myAppFile to (path to me)
tell application "Finder"
    delete myAppFile
end tell
________________
Looking for a Jamf Managed Service Provider? Look no further than Rocketman
________________


Virtual MacAdmins Monthly Meetup - First Friday, Every Month

Hugonaut
Valued Contributor II

if you want to change the name of the computer to something specific, bend this to your will, if you need help let me know, i'm Hugonaut on slack as well.

#!/usr/bin/osascript

--  █████████████████████████████████████████████████████████████████████████████████████████████
-- Get Das infos 
set stafffirstname to text returned of (display dialog "Please type your first name." default answer "")
set stafflastname to text returned of (display dialog "Please type your Last name." default answer "")
set stafffullname to stafffirstname & " " & stafflastname
set staffinitials to (first character of stafffirstname) & (first character of stafflastname)
set serialnumber to do shell script "system_profiler SPHardwareDataType|grep 'Serial Number' -m1|cut -d: -f2|cut -c 2-13" -- they moved stuff around in system-profiler
set os to "-OSHERE"


--   █████████████████████████████████████████████████████████████████████████████████████████████
-- Change computer name 
set compname to "Staff-" & stafffirstname & stafflastname & os


--   █████████████████████████████████████████████████████████████████████████████████████████████
-- Set Ad Privvies
set UNAME to "admin"
set PASSW to "pass"


--  █████████████████████████████████████████████████████████████████████████████████████████████
-- Set Computer name
try
    do shell script "scutil --set ComputerName " & quoted form of compname user name UNAME password PASSW with administrator privileges
    do shell script "scutil --set HostName " & quoted form of compname user name UNAME password PASSW with administrator privileges
    do shell script "scutil --set LocalHostName " & quoted form of compname user name UNAME password PASSW with administrator privileges
end try


--  █████████████████████████████████████████████████████████████████████████████████████████████
-- Change computer name
try
    do shell script "dscl . -create /Users/***USER PATH VARIABLE HERE RealName***" & quoted form of stafffullname user name UNAME password PASSW with administrator privileges
end try

delay 1

try
    do shell script "sudo /usr/local/jamf/bin/jamf recon" user name UNAME password PASSW with administrator privileges
end try

delay 5
________________
Looking for a Jamf Managed Service Provider? Look no further than Rocketman
________________


Virtual MacAdmins Monthly Meetup - First Friday, Every Month