Last active
August 29, 2015 14:12
-
-
Save miyagawa/a8ec98bf98bbd25c1aaf to your computer and use it in GitHub Desktop.
AppleScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 1. TextEdit got an error: Can’t get POSIX file "..." | |
set p to "/path/to/file.txt" | |
tell application "TextEdit" | |
open file (POSIX file p) | |
end tell | |
-- 2. This works | |
tell application "TextEdit" | |
-- use literal | |
open file (POSIX file "/path/to/file.txt") | |
end tell | |
-- 3. This works | |
set p to "/path/to/file.txt" | |
tell application "TextEdit" | |
open file (p as POSIX file) | |
end tell | |
-- 4. This works | |
set p to "/path/to/file.txt" | |
set q to POSIX file p | |
tell application "TextEdit" | |
open file q | |
end tell |
"Path to" will help with hardcoding.
set filePath to POSIX path of (path to desktop as text) & "file.txt"
tell application "TextEdit" to set resultDocument to open filePath
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tell application "TextEdit" to set resultDocument to open "/Users/me/Desktop/file.txt"
-- or
tell application "TextEdit" to set resultDocument to open alias "HD:Users:me:Desktop:file.txt"
-- or
tell application "TextEdit" to set resultDocument to open "HD:Users:me:Desktop:file.txt"
-- or
tell application "Finder" to set myFile to document file "file" of folder "Desktop" of folder "me" of folder "Users" of disk "HD"
tell application "TextEdit" to set resultDocument to open myFile