POSIX-path-alias confusion

Hi,

I’m (completely) new to AS, but getting very intrigued. . . Problem is, that my boss can’t wait around for me to figure it out for myself, so i’m asking this question that might be a bit easy to answer, and hope that you can forgive me for not taking more time trying myself before asking.

Anyways, I want this script to 1: mount a server, 2: copy a file from this server to the computer, overwriting an old one, 3: open a program, 4: wait until the program closes, and then 5: copy a file from the computer to the server, overwriting the old one.

By searching around this lovely forum i’ve actually managed to do it all. . . But (yes, there’s a but, else there would be no point in posting, now would there ?:P) since this script has to run on different computers, i need the path in part 2 and 5 to be relative to the user. I mean, i need “~/” to work… Heh. I’ve found the path to home but since I have no experience, I can’t implement it to my script:


tell application "Finder"
	mount volume "afp://ip_/folder_"
end tell
set ServerSide to "/Volumes/folder/folder2/folder3/file"
set LocalSide to "Users/theuser/Library/Application Support/folder/folder/file"
set LocalSide to ((POSIX file LocalSide) as alias)
set ServerSide to ((POSIX file ServerSide) as alias)
tell application "Finder" to duplicate ServerSide to container of LocalSide with replacing
open application "/Applications/application.app"
tell application "System Events"
	repeat while (name of every application process) contains "application name"
	end repeat
end tell
tell application "Finder" to duplicate LocalSide to container of ServerSide with replacing

that was the version that works for me, but “Users/theuser” needs to be relative. which I cant manage do get working.
And yeah, oh, last thing, the application opens up behind the other windows, any way to change that?

Thanks for your help, looking forward to learning more AS, and sorry for the long post.

set localSide to ((path to home folder) & "Library:Application Support:folder:folder:file") as alias

I would put a delay in your repeat loop or you’ll be thrashing the computer.

Hi,

as the script is for commercial use, ask your boss how much he like to pay for it :wink:

I recommend to use the shell for the copy task
and to use two separated scripts. The first one

mount volume "afp://ip_/folder_"
set fileName to "file"
set ServerSide to "/Volumes/folder/folder2/folder3/"
set LocalSide to POSIX path of (path to application support folder from user domain as text) & "folder/folder/"
do shell script "/bin/cp " & quoted form of (ServerSide & fileName) & space & quoted form of LocalSide
activate application "application"

mounts the volume, copies the file and launches the app. (btw: open is not the proper syntax to launch an app)

For the second one you need a tool like QuickSilver to be able to hook into the ⌘Q command of the app,
which should trigger this


set fileName to "file"
set ServerSide to "/Volumes/folder/folder2/folder3/"
set LocalSide to POSIX path of (path to application support folder from user domain as text) & "folder/folder/"
quit application "application"
do shell script "/bin/cp " & quoted form of (LocalSide & fileName) & space & quoted form of ServerSide

Polling System Events for hours is a waste of time and system resources

Oh darn, only thing i missed was the ()s … and yeah, heh, was just in the middle of finding out how to put delay into the loop… :rolleyes:

Thanks a bunch!

Yeah, not so happy about it myself, so i’ll consider your idea. Thanks for your input, and the “open”-correction.

hmmm…

when i write


set LocalSide to ((path to application support folder from user domain) & "Folder 1:file.xml" as alias)

it comes up with

Can’t make {alias “HD:Users:me:Library:Application Support:”, “Folder 1:file.xml”} into type alias.

which makes it seem like the “&” isn’t working quite as supposed?

If I try the shell script i get “Expected end of line, etc. but found “””." at

do shell script "/bin/cp "

, both with and without spaces between cp and " …

what am I doing wrong guys?

path to returns an alias and a string cannot coerced to an alias, this works


set LocalSide to ((path to application support folder from user domain as text) & "Folder 1:file.xml" as alias)

The syntax of the shell script I posted above is correct, there must be a space character after cp

thanks again!