in reference to my original goal outlined in http://macscripter.net/viewtopic.php?id=35819:
this snippet of an Applescript gives me problems. My goal is to find out if a user has the folder ~/Library/Application Support/SierraHelp and create it when it doesn’t exist. Same for the subfolder captures of ~/Library/Application Support/SierraHelp.
Since I can’t know the username or the HD name, I can’t just write the alias.
My first attempt obviously fails because “(AppSupFolder & “SierraHelp”)” doesn’t give a valid alias when the SierraHelp folder already exists (if both folders are not existing the script works):
set AppSupFolder to path to application support from user domain
tell application "Finder"
if not (exists folder "SierraHelp" of AppSupFolder) then
set sierraFolder to make new folder at AppSupFolder with properties {name:"SierraHelp"}
else
set sierraFolder to (AppSupFolder & "SierraHelp")
end if
if not (exists folder "captures" of sierraFolder) then
set capturesFolder to (make new folder at sierraFolder with properties {name:"captures"}) as text
else
set capturesFolder to (sierraFolder & "captures") as text
end if
end tell
my next attempt was to convert the POSIX path back to the alias
set AppSupFolder to path to application support from user domain
set AppSupFolderPosix to POSIX path of AppSupFolder
tell application "Finder"
if not (exists folder "SierraHelp" of AppSupFolder) then
set sierraFolder to make new folder at AppSupFolder with properties {name:"SierraHelp"}
else
set sierraFolderPOSIX to (AppSupFolderPosix & "SierraHelp/")
display dialog sierraFolderPOSIX
set sierraFolder to (POSIX file sierraFolderPOSIX) as text
end if
if not (exists folder "captures" of sierraFolder) then
set capturesFolder to (make new folder at sierraFolder with properties {name:"captures"}) as text
else
set capturesFolder to (sierraFolder & "captures") as text --> as the script bombs earlier this part got left in
end if
set capturesFolderPosix to POSIX path of capturesFolder
display dialog "\"" & capturesFolderPosix & "\""
end tell
The line
set sierraFolder to (POSIX file sierraFolderPOSIX) as text
gives me grieve since it won’t work (žPOSIX file "/Users/Dominus/Library/Application Support/SierraHelp/"“cannot be read”) without as text/string but with either text or string I don’t have an alias to check against when I check whether the captures folder exists (error "“captures cannot be converted to typ integer” (or something like that in German)).
What am I doing wrong now?
Another strange problem was that when I tested this a bit the AppleScript would not always “know” that the SierraHelp folder was already deleted. By running the first if part of the script the folder got created, then I ran the script again and since the folder existed set the variable (I had some display dialogs in there to make sure which part got run). When I now deleted the folder SierraHelp and ran the script again, it assumed that the folder still existed and didn’t create it for some time.
Edit: just about to go to bed but I wondered whether a POSIX path with ~/library… Would also correctly convert to an alias via POSIX file. And whether a POSIX path and its conversion need to actually exist when being set to a variable… That would change things