• 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
Applescript access privileges
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Applescript access privileges


  • Subject: Applescript access privileges
  • From: "Troy, Drew" <email@hidden>
  • Date: Wed, 22 Oct 2008 09:01:57 -0400
  • Acceptlanguage: en-US
  • Thread-topic: Applescript access privileges

Hi everyone, I am been trying to write this code for the past few weeks.  Its purpose is to send inventory information about clients to our Altiris server.   The problem that I am having is highlighted below about ¾ of the way down that page, where I am telling the application TextEdit to create a file right to it and save it.  The script seems to work on my machine and a couple of my test machines.  The error that I am getting says “the document untitled 2 could not be exported as muwoner.nsi you don’t have appropriate access privileges”. I don’t know if it is some strange rights problems or maybe that the folder is hidden.  Altiris runs the script and is supposed to do so as root.  Can anyone help?

 

--download csv file from online location

display dialog "You will need to enter your local Admin ID and Password during this script."

set download_url to "https://software.muohio.edu/updates/testdept.csv"

tell application "URL Access Scripting"

            activate

            set the_file to "./testdept.csv"

            download download_url to the_file with progress

            quit

end tell

 

set user_name to display dialog ¬

            "What is your unique ID?" default answer ¬

            "null" buttons {"OK", "Stop"} default button "OK"

set button_name to button returned of user_name

if button_name is "OK" then

            set strname to text returned of user_name

else

            display dialog "Please input division name."

end if

-- Choose File

set CSV_File to ":testdept.csv" as text

 

-- Reads file to memory

-- Read Disivions and their departments

 

-- set CSV_lines to read file CSV_File using delimiter {return}

set file_data to read file CSV_File

-- make a list of lines from the file

set file_lines to paragraphs of file_data

 

set line_count to (count file_lines)

 

set division_list to items 1 through (line_count - 1) of file_lines

-- division_list is {"SEAS,CSA,ECE...","Arts and Science,CHM,COM...", etc}

-- display dialog "division list is " & division_list

 

set function_list to item line_count of file_lines

-- function list is the last line of the file

-- display dialog "function list is " & function_list

 

-- make a list of divisions

set divisions to {}

repeat with ThisLine in division_list

            set end of divisions to GetTextItem(ThisLine as text, ",", 1)

end repeat

-- divisions list is {SEAS, Arts and Science, etc}

 

-- Ask user for the division

set division to (choose from list divisions with prompt "Select a Division") as string

 

-- figure out the index for the division

set number_of_divisions to (count divisions)

repeat with i from 1 to number_of_divisions

            set single_division to item i of divisions

            if single_division as text is division then

                         set division_index to i

                         exit repeat

            end if

end repeat

 

-- Get the line of the file with departments for the for the desired division

set division_line to item division_index of file_lines

--display dialog "divison index" & division_index

 

-- dept_count is the number of departments

-- Make a list of the departments

set text item delimiters to ","

set temp_depts to text items of division_line

set dept_count to count temp_depts

set departments to items 2 thru dept_count of temp_depts

--repeat with i from 2 to dept_count + 1

--         set end of departments to GetTextItem(division_line as text, ",", i)

--end repeat

 

-- Ask user for the department

set department to (choose from list departments with prompt "Select a Department") as string

-- display dialog "Your division is " & division & " your department is " & department

 

 

--Make a list of the functions

set functions to text items of function_list

 

--Ask user for the function

set function to (choose from list functions with prompt "Select a Function") as string

-- display dialog "you selected function " & function

 

 

-- set sub function yes or no

set subfunction to {yes, no}

 

set strSubFunc to (choose from list subfunction with prompt "Is this the primary computer?") as string

-- display dialog (strSubFunc as string)

 

set dcsv_file to alias ":testdept.csv"

tell application "Finder"

            activate

            delete file dcsv_file

end tell

 

--Search and Replace text (for nsi file)

set nsi_File to ":Applications:Utilities:Altiris:NSAgent:.var:packages:{173E2A9A-DAF7-4016-BE78-B35EB3D96AEB}:MUOwner.nsi" as text

set file_data to read file nsi_File

 

set text item delimiters to "ReplaceWithName"

set textItems to text items of file_data

set text item delimiters to strname

set file_data to textItems as string

 

set text item delimiters to "ReplaceWithDivision"

set textItems to text items of file_data

set text item delimiters to division

set file_data to textItems as string

 

set text item delimiters to "ReplaceWithDepartment"

set textItems to text items of file_data

set text item delimiters to department

set file_data to textItems as string

 

set text item delimiters to "ReplaceWithFunction"

set textItems to text items of file_data

set text item delimiters to function

set file_data to textItems as string

 

set text item delimiters to "ReplaceWithSubfunction"

set textItems to text items of file_data

set text item delimiters to strSubFunc

set file_data to textItems as string

 

tell application "TextEdit"

            make new document

            set text of document 1 to file_data

            save document 1 in ":Applications:Utilities:Altiris:NSAgent:.var:queue:MUOwner.nsi"

            quit saving no

end tell

 

--set f to alias file ":Applications:Utilities:Altiris:NSAgent:.var:queue:MUOwner.nsi"

-- set f to a reference to file ((path to desktop as string) & "justTesting")

--open for access f with write permission

--write file_data as text to f

--close access f

 

 

do shell script "exec /Applications/Utilities/Altiris/NSAgent/.var/packages/\\{173E2A9A-DAF7-4016-BE78-B35EB3D96AEB\\}/mu-collectinv.sh"

 

on GetTextItem(ThisString, ThisDelim, ThisItem)

            --ThisString -> String to look in

            --ThisDelim -> Text element that delimit the string

            --ThisItem -> Number of the element to return

            copy the text item delimiters to OldDelims

            set the text item delimiters to ThisDelim

            if class of ThisItem is list then

                         set fromItem to (item 1 of ThisItem) as integer

                         set toitem to (item 2 of ThisItem) as integer

                         --display dialog ThisItem

                         set arrItem to (text items fromItem thru toitem of ThisString)

            else

                         set arrItem to every text item of ThisString

            end if

            set the text item delimiters to OldDelims

           

           

            if class of ThisItem is list then

                         return arrItem as text

                        

            else

                         if ThisItem is not equal to 0 then

                                    

                                     return (item ThisItem of arrItem) as text

                         else

                                     return arrItem -- return every items

                                    

                                    

                                    

                         end if

            end if

end GetTextItem

 

Thanks,

Drew

MU Ohio

 

 

 

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Translating .MOD Files
  • Next by Date: Bad Characters in a File Name
  • Previous by thread: Translating .MOD Files
  • Next by thread: Path to syntax question
  • Index(es):
    • Date
    • Thread