Sorry for the late reply, I was typing one up yesterday but I had to leave and I lost it.
sorry for the confusion but I can get Finder to open the file if I set the path as a variable i.e.
tell application "System Events" to set parentFolder to POSIX path of container of (path to me)
set folder1 to "/folder1"
set myPath to parentFolder & folder1
tell application "Finder" to open POSIX file myPath & "/file.extention"
but what I am trying to do is.
tell application "System Events" to set parentFolder to POSIX path of container of (path to me)
set folder1 to "/folder1"
set fileDocument to "/file.extention"
set pathtoFile to parentFolder & folder1 & fileDocument
tell application "Finder" to open POSIX file pathtoFile
I get the error
“Can’t get POSIX file of “/Users/server/Desktop/folder1/file.extention”.”
I am trying to do this because something that the user selects from excel contains the file path and the file path exists because if I copy and past the file path from the error into tell application “Finder” to open POSIX file “path/from/error.extention” it works fine
EDIT:
There are 2 files to choose from at the end of every path possible.
here is the actual script I have been using and I am not sure what is wrong with it.
tell application "System Events" to set parentFolder to POSIX path of container of (path to me)
set ddResult to button returned of (display dialog "Select Product Code" buttons {"Cancel", "Next"} default button "Next" cancel button "Cancel")
tell application "Microsoft Excel"
if ddResult = "Next" then
set pcode to value of selection as text
end if
end tell
display dialog "Mesh?" buttons {"No", "Yes"} default button "No"
if result = {button returned:"Yes"} then
set labelFile to "mesh.laba"
else if result = {button returned:"No"} then
set labelFile to "nomesh.laba"
end if
set openLabel to getLabel(pcode, parentFolder, labelFile)
--------------------
-->> LABEL HANDLER
--------------------
on getLabel(pcode, parentFolder, labelFile)
if pcode contains "EF" then
set path1 to "/EF"
else if pcode contains "JF" then
set path1 to "/JF"
else if pcode contains "CF" then
set path1 to "/CF"
else if pcode contains "UF" then
set path1 to "/UF"
end if
if pcode contains "LG" then
set path2 to "/LG"
else if pcode contains "MD" then
set path2 to "/MD"
else if pcode contains "ST" then
set path2 to "/ST"
else if pcode contains "SM" then
set path2 to "/SM"
end if
if pcode contains "P" then
set path3 to "/P/"
else if pcode contains "E" then
set path3 to "/E/"
end if
set labelPath to parentFolder & "/labels" & path2 & path1 & path3 & labelFile
tell application "Finder" to open POSIX file of labelPath
end getLabel
EDIT 2: the path2 & path1 are the correct way round I found I made the folders the wrong way so for testing I just swapped them around from path1 & path2 to path2 & path1
set foldervariable to /Users/user/desktop/folder1/folder2
set filevariable to "/file.extention"
set folderfilevariable to foldervariable & filevariable
tell application "Finder" open POSIX file folderfilevariable as string
It works although I still get “–> error number -1728 from POSIX file “/Users/user/desktop/folder1/folder2/file.extention”” in the log but the file opens.
This is a version which works with HFS paths (colon separated) instead of POSIX paths.
If the file at the composed file path does not exist, a message will be displayed
tell application "System Events" to set parentFolder to path of container of (path to me)
set ddResult to button returned of (display dialog "Select Product Code" buttons {"Cancel", "Next"} default button "Next" cancel button "Cancel")
tell application "Microsoft Excel"
if ddResult = "Next" then
set pcode to value of selection as text
end if
end tell
display dialog "Mesh?" buttons {"No", "Yes"} default button "No"
if result = {button returned:"Yes"} then
set labelFile to "mesh.laba"
else if result = {button returned:"No"} then
set labelFile to "nomesh.laba"
end if
set openLabel to getLabel(pcode)
set filePath to parentFolder & "labels" & ":" & openLabel & ":" & labelFile
tell application "Finder"
if exists file filePath then
open file filePath
else
display dialog "The file '" & filePath & "' does not exist"
end if
end tell
--------------------
-->> LABEL HANDLER
--------------------
on getLabel(pcode)
if pcode contains "EF" then
set path1 to "EF"
else if pcode contains "JF" then
set path1 to "JF"
else if pcode contains "CF" then
set path1 to "CF"
else if pcode contains "UF" then
set path1 to "UF"
end if
if pcode contains "LG" then
set path2 to "LG"
else if pcode contains "MD" then
set path2 to "MD"
else if pcode contains "ST" then
set path2 to "ST"
else if pcode contains "SM" then
set path2 to "SM"
end if
if pcode contains "P" then
set path3 to "P"
else if pcode contains "E" then
set path3 to "E"
end if
return path2 & ":" & path1 & ":" & path3
end getLabel
I’m pretty sure that snippet worked when it was written (a couple of years ago), but the problem doesn’t relate to the Finder recognizing a POSIX path (which it doesn’t). POSIX file produces a «class furl», but it looks like you now need to use it as a coercion in this case, rather than as a specifier.
tell application "Finder" to open (pathvariable & "/Lorikeet.jpg") as POSIX file
POSIX file still seems to work outside a Finder tell block OK:
set theFile to POSIX file (pathvariable & "/Lorikeet.jpg")
tell application "Finder" to open theFile