Help With POSIX File Path to Windows Share

Using AppleScript I am trying to write a file named redirect.htm to a Windows network share named LINKS. I can write the file to the Macbook desktop and then copy it to the network share using Finder, but I cannot figure out how to write the file directly to the Windows folder. The code looks something like this:

tell application “Safari”
tell document 1
set JavaURL to “self.location.replace("” & my escapeURL(URL) & “");”
end tell
end tell

set OutputPath to (path to desktop as Unicode text) & “LinkTo.htm”
set fRef to (open for access file OutputPath with write permission)
try
set eof fRef to 0
write “” & return to fRef
end try
close access fRef

After copying the resulting file from the Mac desktop to the Windows share, the Finder Info shows “Where: /Volumes/LINKS; Server: cifs://HOME;administrator@LIFEBOOK/LINKS” (the Windows PC name is LIFEBOOK, the workgroup name HOME, the share name LINKS). I have tried changing the SET OutputPath to various combinations such as: set OutputPath to “//LINKS/redirect.htm” and “cifs://HOME;administrator@LIFEBOOK/LINKS/redirect.htm”.

As you might suspect I am new to AppleScript. Any guidance would be appreciated!

Thanks,
Paul Jones

Model: Macbook
AppleScript: 1.10.7
Browser: Safari 523.12.2
Operating System: Mac OS X (10.4)

Hi Paul,

welcome to MacScripter :slight_smile:

try this at the end of your script


if "LINKS" is in (do shell script "/bin/ls /Volumes/") then
	do shell script "/bin/mv " & quoted form of POSIX path of OutputPath & space & "/Volumes/LINKS/redirect.htm"
end if

I recommend to create the text file locally and then move it to the shared volume

Thanks for your response. I think I found a reasonable solution by searching the forum for similar responses (and a little trial and error). In case you or anyone else is interested it wound up something like this:

– Mount the LINKS share on the LIFEBOOK computer
set mountedVolume to mount volume “smb://LIFEBOOK/LINKS” as user name “" with password "

– Open LINKS\LinkTo.htm file for output
set OutputPath to “LINKS:LinkTo.htm”
set fRef to (open for access file OutputPath with write permission)

– Write the Linkto.htm Javascript file
try
set eof fRef to 0
write “” & return to fRef
end try
close access fRef

– Unmount (eject) the LINKS share
tell application “Finder” to eject “LINKS”

I’m not sure if this is the best looking code, but it does work.

Paul Jones