Skip to content

Instantly share code, notes, and snippets.

@miyagawa
Last active August 29, 2015 14:12
Show Gist options
  • Save miyagawa/a8ec98bf98bbd25c1aaf to your computer and use it in GitHub Desktop.
Save miyagawa/a8ec98bf98bbd25c1aaf to your computer and use it in GitHub Desktop.
AppleScript
-- 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
@johneday
Copy link

johneday commented Jan 7, 2015

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

@johneday
Copy link

johneday commented Jan 7, 2015

"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