applescript

Relative file paths with Applescript

别来无恙 提交于 2019-12-18 03:42:05
问题 I'm trying to make an Applescript that will open a file on a user's computer without knowing the hard drive or user name, presuming the file is in the same place in the user directory. tell application "Finder" to open "/Users/jim/Dropbox/Getting Started.pdf" as POSIX file works great, whereas tell application "Finder" to open "~/Dropbox/Getting Started.pdf" as POSIX file fails. Is there any way to accomplish this simply? 回答1: You can't use tilde paths in AppleScript basically because POSIX

Relative file paths with Applescript

怎甘沉沦 提交于 2019-12-18 03:41:02
问题 I'm trying to make an Applescript that will open a file on a user's computer without knowing the hard drive or user name, presuming the file is in the same place in the user directory. tell application "Finder" to open "/Users/jim/Dropbox/Getting Started.pdf" as POSIX file works great, whereas tell application "Finder" to open "~/Dropbox/Getting Started.pdf" as POSIX file fails. Is there any way to accomplish this simply? 回答1: You can't use tilde paths in AppleScript basically because POSIX

Open URL in new Safari tab with AppleScript

為{幸葍}努か 提交于 2019-12-17 22:27:24
问题 Is it possible to use AppleScript to open a link in a new tab in Safari? 回答1: This will work: tell application "Safari" tell window 1 set current tab to (make new tab with properties {URL:"http://www.stackoverflow.com"}) end tell end tell 回答2: I think this also does what you asked for, but it is much shorter and is less browser-specific: do shell script "open http://www.webpagehere.com" This will open the specified URL in your default browser. And if you explicitly want to open it in Safari,

Launch OSX Finder window with specific files selected

只谈情不闲聊 提交于 2019-12-17 21:50:39
问题 I'm trying to programmatically launch an OSX Finder window from an Xcode project. I need the window to open to a specific folder and have specific files within that folder automatically selected. Does anyone know how to do this in either objective c, applescript, or Finder command-line parameters? Thanks! 回答1: Objective-C version: NSArray *fileURLs = [NSArray arrayWithObjects:fileURL1, /* ... */ nil]; [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:fileURLs]; 回答2: $ open -R

Applescript: Get filenames in folder without extension

寵の児 提交于 2019-12-17 21:02:36
问题 I can get the names of all files in a folder by doing this: tell application "Finder" set myFiles to name of every file of somePath end tell How can I change the strings in myFiles so that they do not include the file extension? I could for example get {"foo.mov", "bar.mov"} , but would like to have {"foo", "bar"} . Current solution Based on the accepted answer I came up with the code below. Let me know if it can be made cleaner or more efficient somehow. -- Gets a list of filenames from the

Finder update/refresh applescript not working in 10.8

不羁岁月 提交于 2019-12-17 19:54:20
问题 I have been using apple script for updating display for files and folders in finder. This is simplified version of that script: tell application "Finder" tell window 1 to update items end tell I can see that since 10.8 (Mountain Lion) update command is not properly executed or is not executed at all. Until 10.8 everything was working perfectly - Immediately after update command all icons got redrawn. I use this for showing overlay icons. Have any of you encountered same problem? I blame

Quit All Applications using Applescript?

我只是一个虾纸丫 提交于 2019-12-17 18:53:21
问题 How would I quit all running user applications using Applescript? 回答1: It's okay... I think I found my answer: tell application "System Events" to set the visible of every process to true set white_list to {"Finder"} try tell application "Finder" set process_list to the name of every process whose visible is true end tell repeat with i from 1 to (number of items in process_list) set this_process to item i of the process_list if this_process is not in white_list then tell application this

OSX Lion AppleScript : How to get current space # from mission control?

我只是一个虾纸丫 提交于 2019-12-17 17:24:47
问题 I'm trying to figure out how to get the current space # from mission control. Source would be helpful, but more helpful would be info on how to figure this out myself. I've written a few applescripts, but more often than not it seems like any time I need to do something new (that I can't find dictionary documentation for) it falls under the category of "tell this specific app (e.g. "System Events") this very specific thing" and I've no clue how I would actually figure that out. Specifically

Passing variables to an AppleScript

走远了吗. 提交于 2019-12-17 17:01:02
问题 The code to run my AppleScript in Xcode is the following: NSString *path = [[NSBundle mainBundle] pathForResource:@"Script" ofType:@"scpt"]; NSAppleScript *script = [[NSAppleScript alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil]; [script executeAndReturnError:nil]; Before executing it, I was wondering if it was possible to set some variables up for it to use. In other words, I want to pass variables from my app to an AppleScript. 回答1: You could use the method: - (id

is there something akin to regEx in applescript, and if not, what's the alternative?

放肆的年华 提交于 2019-12-17 15:28:04
问题 I need to parse the first 10 chars of a file name to see if they are all digits. The obvious way to do this is fileName =~ m/^\d{10}/ but I'm not seeing anything regExy in the applescript reference, so, I'm curious what other options I have to do this validation. 回答1: Don't despair, since OSX you can also access sed and grep through "do shell script". So: set thecommandstring to "echo \"" & filename & "\"|sed \"s/[0-9]\\{10\\}/*good*(&)/\"" as string set sedResult to do shell script