Applescript - Pathing to a specific (non-desktop) folder location

53 Views Asked by At

I am currently using this line of code:

set logFilePath to ((path to desktop as text) & "crash.log") as text

to path to the desktop. However, I want to path to another file path, such as ~/Library/App Support/CrManager/logs

I tried doing:

set logFilePath to ((path to ~/Library/App Support/CrManager/logs as text) & "crash.log") as text

but it did not work. I also tried:

tell application "Finder" set logFilePath to (folder "saves" of ~/Library/App Support/CrManager/logs as text) & ¬ "crash.log" as alias end tell

but that failed, too.

1

There are 1 best solutions below

0
On

Maybe this will help.

set appSupportFolder to ((path to library folder from user domain as text) ¬
    & "Application Support:")
set crManagerLogsFolder to "CrManager:Logs:"

try
    -- checks if ~/Library/Application Support/CrManager/logs exists
    alias ((appSupportFolder & crManagerLogsFolder) as text)
on error
    -- creates ~/Library/Application Support/CrManager/logs folder if it doesnt exist
    do shell script "mkdir -p " & quoted form of POSIX path of ¬
        (appSupportFolder & crManagerLogsFolder)
    -- creates an empty crash.log file
    do shell script "touch " & quoted form of POSIX path of ¬
        (appSupportFolder & crManagerLogsFolder) & "/crash.log"
end try

-- use whichever is convenient for you
set logFilePathAsAlias to (appSupportFolder & crManagerLogsFolder) & "crash.log" as alias
set logFilePathAsPosixPath to POSIX path of ((appSupportFolder & crManagerLogsFolder) & "crash.log")