The window bounds are a list of coordinates {left, top, right, bottom}. You probably intended "400" to be the width, but it's the position of the right edge of the window and 400 is to the left of 1105, so you get a minimum width window. Change 400 to 1105 plus the desired width, e.g., 1505.
But before you pursue this further, Terminal has a better solution for this: Window Groups. If you set up a group of windows and save them as a Window Group, each time you open that group it will create windows with the same layout and appearance.
Window > Save Windows as Group…
You can even tell Terminal to open a selected window group at startup:
Terminal > Preferences > Startup > On startup, open: > Window group:
(As a shortcut, when creating a window group there's a checkbox for making it the startup group.)
To automatically run particular commands in those windows, you can create custom settings profiles and specify the command with
Terminal > Preferences > Settings > [profile] > Shell > Startup > Run command:
then create each window with the appropriate profile.
Going further, in Mac OS X Lion 10.7 you can have window groups automatically restore commands without creating custom profiles, by creating the terminals using
Shell > New Command
instead of running the command inside the terminal shell. When creating the window group, you can check "Restore all commands". (By default, it will restore a small set of "safe" commands, but you must explicitly tell it if you want it to re-run all commands when opening the group.)
Moreover, Lion Terminal supports Resume and will automatically restore all your windows each time you open Terminal. It will even restore "safe" commands for terminals created with New Command.
Copying of files in Applescript is best done either through System Events or Finder, using the duplicate … to
command, i.e.
tell application "System Events" to duplicate sourceFile to targetFolder
where both sourceFile
and targetFolder
need to be the correct object type for the application used – meaning disk item or finder item (both objects can be created from AppleScript alias objects, or textual path values with a bit of type coercion – I’d add the details, but you have not stated how the paths to both are stored / acquired in your script).
A few notes on your code:
- There is no need to use globals when you have defined them as properties already. AppleScript properties are script scoped and persist across execution – they are only reset when the script is recompiled. If you assign those that need user setting
missing value
when declaring, you can even check if they are already set and skip re-prompting the user (there would be an even more comfortable and secure solution if Apple hadn’t deprecated Keychain Access Scripting).
There is no need for the repeated assignments and recursive call in your connectToServer()
handler. The following code
set timeOutCounter to 0
repeat while (list disks) does not contain serverName and timeOutCounter is less than timeOutInterval
-- mount drive
delay someInterval -- recommended, so you don’t hectically loop
set timeOutCounter to timeOutCounter + someInterval -- time out loop
end repeat
will try to connect in the interval defined by someInterval
, until the mount is available or timeOutInterval
is reached (assuming these values are declared. As properties, best – see above).
- You might also want to offer your user a more comfortable way of selecting the target folder than typing a folder name from memory. Check out Standard Additions’s AppleScript dictionary for the
choose folder
command.
- Finally, but that is mainly a matter of taste and coding style, I’d rather move the
display dialog
command into its own handler and call that, if needed repeatedly, from the script body, than use a C style mainLoop
handler. I’ve found that, generally speaking, AppleScript runs out of Stack space easily when recursing and can get very confused about variable assignments, so it is a good idea to avoid recursive constructs where they are not necessary.
Best Answer
The correct syntax would be
smb://[<user>@]<workgroup>[:<port>][/]
To answer your second question: