Resolved Applescript Frontend help

Discussion in 'Mac Programming' started by h1068, Jun 10, 2012.

  1. h1068, Jun 10, 2012
    Last edited: Jun 13, 2012

    macrumors newbie

    Joined:
    Jun 10, 2012
    #1
    I have a script that
    ask for server, user name,password
    And then mounts afp share.

    how can i make a window that displays all.
    ex.

    Server select from list: Server 1
    Server 2
    Server 3
    Username: user input
    Password: user input

    CONNECT




    scriptingnewb*

    [RESOLVED] I used Pashua to create the dialog
    http://www.bluem.net/en/mac/pashua/
    Thank you!
     
  2. macrumors 68040

    Joined:
    Feb 2, 2008
  3. thread starter macrumors newbie

    Joined:
    Jun 10, 2012
    #3
    Lol,
    the idea is to make an alternative login to a mac sever.
    after it connects the next part wipes the local user home directory with exception of library and maps it over to to the servers.
     
  4. macrumors 68040

    Joined:
    Feb 2, 2008
    #4
    Are you talking about your script now? The reason that I mentioned it, is that it does everything you requested, including favorite server list and it's built right into Finder. :)

    You probably need to post your script here if you have problems with it.
     
  5. macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #5
    What OS are you running? To get everything in one window you are looking at using Xcode (which isn't too difficult depending on what kind of programming you are familiar with), or a third party utility such as Pashua.
     
  6. thread starter macrumors newbie

    Joined:
    Jun 10, 2012
    #6
    The rest of the script works fine.
    Command k is good, but that is not exactly what I'm looking to do.

    this is a login item that runs when a student logs in on a local account.

    i need my applescript dialog boxes to display all at once in one window.

    ----------

    I'm using 10.6.8. Only know code from googling examples.
     
  7. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #7
    Red Menace beat me to it. You can also use Smile to build custom dialogs.
     

    Attached Files:

  8. macrumors 68040

    Joined:
    Feb 2, 2008
    #8
    I see, that adds some context to the first post. It's a pity to create ad-hoc solutions to things that are provided by the system. :)
     
  9. h1068, Jun 10, 2012
    Last edited: Jun 10, 2012

    thread starter macrumors newbie

    Joined:
    Jun 10, 2012
    #9
    I installed Paschua,

    The applescript I want to run is at the bottom... Is this right?

    Can I delete any of this code?

    Code:
    set config to "
    the_server.type = popup
    the_server.label = Please select your server.
    the_server.width = 310
    the_server.option = od1
    the_server.option = od2
    the_server.option = od3
    the_server.option = od
    the_server.default = od
    
    
    the_user.type = textfield
    the_user.label = Please enter your username.
    the_user.default = 
    the_user.width = 340
    
    the_pass.type = textfield
    the_pass.label = Please enter your password.
    the_pass.default = 
    the_pass.width = 340
    
    "
    
    
    
    
    
    
    
    -- Call Pashua and save the resulting record in pashuaResult
    set pashuaResult to pashua_run(config, "", "")
    activate
    
    
    
    -- Glue code for interfacing from AppleScript to Pashua. Written by
    -- Carsten Blüm <carsten@bluem.net>, 10/2003-01/2006, with improvements
    -- contributed by Eddy Roosnek and Hans Haesler. You can use or modify
    -- this handler any way you like in your own scripts.
    -- Argument 1: Configuration string / window description
    -- Argument 2: Encoding to use; if empty, Pashua assumes "macroman"
    -- Argument 3: Folder that contains Pashua.app; if empty, default locations are searched
    on pashua_run(config, encoding, appdir)
    	
    	-- Create path for temporary file
    	set AppleScript's text item delimiters to ""
    	set tmpfile to ((path to temporary items folder as string) & "Pashua_" & (characters 3 thru end of ((random number) as string)) as string)
    	
    	-- Write temporary file and fill it with the configuration string
    	set fhandle to open for access tmpfile with write permission
    	write (config as string) to fhandle
    	close access fhandle
    	
    	-- Get temporary file's POSIX path
    	set posixtmpfile to POSIX path of tmpfile
    	
    	set diskPath to (path to startup disk as string)
    	set userPath to path to "cusr" as string
    	set myself to (path to me as string)
    	tell application "Finder" to set myParentPath to (container of alias myself as string)
    	
    	-- Try to find Pashua application
    	tell application "Finder"
    		-- Try to find it in the directory supplied as argument to this handler
    		if appdir is not "" then
    			if last character of appdir = ":" then
    				set dirsep to ""
    			else
    				set dirsep to ":"
    			end if
    			if item (appdir & dirsep & "Pashua.app") exists then
    				set pashua to appdir & dirsep & "Pashua.app:"
    			end if
    			-- Try to find it in this script application bundle
    		else if item (myself & "Contents:MacOS:Pashua") exists then
    			set pashua to myself
    			-- Try to find it in this script's parent's path
    		else if item (myParentPath & "Pashua.app") exists then
    			set pashua to (myParentPath & "Pashua.app:")
    			-- Try to find it in global application folder
    		else if item (diskPath & "Applications:Pashua.app") exists then
    			set pashua to (diskPath & "Applications:Pashua.app:")
    			-- Try to find it in user's application folder
    		else if item (userPath & "Applications:Pashua.app") exists then
    			set pashua to (userPath & "Applications:Pashua.app:")
    		else
    			display dialog "I can't find the Pashua application." & return & "It looks like Pashua is neither in one of the standard locations nor in the folder this AppleScript is in." buttons {"OK"} default button 1 with icon stop
    			return -1
    		end if
    	end tell
    	
    	-- Append binary position inside app bundle to "regular" path
    	-- and convert path from HFS to POSIX representation
    	set pashuabinary to (POSIX path of pashua) & "Contents/MacOS/Pashua"
    	
    	-- Optionally, define the encoding as command-line argument
    	if encoding = "" then
    		set encodingArg to ""
    	else
    		set encodingArg to "-e " & encoding & " "
    	end if
    	
    	-- Execute pashua and get the string returned
    	set pashuaCall to "'" & pashuabinary & "' " & encodingArg & "'" & posixtmpfile & "'"
    	set pashuaResult to do shell script (pashuaCall)
    	
    	-- Delete the temporary file
    	tell application "Finder" to delete tmpfile
    	
    	-- Check whether the dialog was submitted at all.
    	-- If this is not the case, return an empty list
    	if pashuaResult = "" then
    		return {}
    	end if
    	
    	-- Parse the result
    	set AppleScript's text item delimiters to return
    	set resultLines to text items of pashuaResult
    	set AppleScript's text item delimiters to ""
    	set recordComponents to {}
    	repeat with currentLine in resultLines
    		set eqpos to offset of "=" in currentLine
    		if eqpos is not 0 then
    			set varKey to word 1 of currentLine
    			try
    				set varValue to (text (eqpos + 1) thru end of currentLine)
    				-- Quote any quotation marks in varValue with a backslash.
    				-- The proper way to do this would be a handler, but as
    				-- all code for interfacing to Pashua should be as compact
    				-- as possible, we rather do it inline
    				set AppleScript's text item delimiters to "\""
    				set textItems to every text item of varValue
    				set AppleScript's text item delimiters to "\\\""
    				set varValue to textItems as string
    				set AppleScript's text item delimiters to ""
    			on error
    				set varValue to ""
    			end try
    			copy (varKey & ":\"" & varValue & "\"") to end of recordComponents
    		end if
    	end repeat
    	
    	-- Return the record we read from the tmpfile
    	set AppleScript's text item delimiters to ", "
    	set resultList to (run script "return {" & (recordComponents as string) & "}")
    	set AppleScript's text item delimiters to {""}
    	return resultList
    	
    	tell application "Finder"
    		mount volume "afp://" & the_user & ":" & the_pass & "@" & the_server & "/" & the_user
    		
    	end tell
    end pashua_run
    
     
  10. kryten2, Jun 10, 2012
    Last edited: Jun 11, 2012

    macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #10
    Comment out eg --return resultList.
    You might want to change your second element type:textfield into an element type:password
     
  11. thread starter macrumors newbie

    Joined:
    Jun 10, 2012
    #11
    Thanks I got my menu working, and the variables push through to my applescript.:)
     

Share This Page