I'm trying to use scripting bridge to communicate with FileMaker pro 11, I can get it to launch the App, open the correct database file but can't get any further.
Has anyone got an example scripting bridge file for FileMaker Pro, once I can get my head around the communication between the 2 I should be OK.
I want to convert my app written in Applescript Studio to Objective C.
I know Objective C but can get my head around the communication between FMP.
A while back I had to control iTunes from a Cocoa app using AppleScript and I used NSAppleScript. I wasn't aware of the Scripting Bridge, and I'll take a look at it, but it was pretty straightforward with NSAppleScript:
NSString *source = #"tell application \"iTunes\" to set sound volume to sound volume - 1";
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:source];
[script executeAndReturnError:nil];
I never had any trouble controlling iTunes in this manner and I'm sure it would work with FileMaker as well.
One thing I'll mention that made writing the code a tiny bit easier was creating a category on NSAppleScript with the following method:
+ (NSAppleEventDescriptor *)executeWithSource:(NSString *)source {
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:source];
return [script executeAndReturnError:nil];
}
That turned my scripting code into
[NSAppleScript executeWithSource:#"tell application \"iTunes\" ..."];
Related
When I used UIImagePickerController on ios <= 9, I didn't see any issues.
On ios 10 I got strange message. I noticed this massage appear after using any code from Photos.framework. (for example checking PHPhotoLibrary status )
Class PLBuildVersion is implemented in both
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices
(0x12049a910) and
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices
(0x1202c4210). One of the two will be used. Which one is undefined.
I found similar issue on stackoverflow
Class PLBuildVersion is implemented in both frameworks
I didn't pay attention about it to some moments while I begin get randomly such crash
(about 1 crash on 15-20 using of UIImagePickerController):
I'm not sure but I think it depend on log message(i.e message above).
It's sdk bug and issue have opened on Apple Radar.
Here my code for invoking UIImagePickerController:
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
self.imagePicker.allowsEditing = allowEditing;
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[vc presentViewController: self.imagePicker animated: YES completion: nil];
My main question is: How can I resolve this issue right now? (Seems like Apple didn't hurry up to resolve it).
I wouldn't like creating custom image picker (without 100% working guarantee)
Are somebody faced with such issue?
Thanks in advance.
I decided try open source alternative for UIImagePickerController.
I go through list in this post How to select Multiple images from UIImagePickerController and integrated this one CTAssetsPickerController.
Log message still appear, but I'm testing it, there are no any issues for now.
Is there a way to close running applications in swift? For instance, if the application I create needs to close safari.
Here's a Swift 5 version for closing running applications without using AppleScript (AppleScript is a perfect way but it isn't the only way), Safari is used as the example in this case:
let runningApplications = NSWorkspace.shared.runningApplications
if let safari = runningApplications.first(where: { (application) in
return application.bundleIdentifier == "com.apple.Safari" && application.bundleURL == URL(fileURLWithPath: NSWorkspace.shared.fullPath(forApplication: "Safari")!)
}) {
// option 1
safari.terminate()
// option 2
kill(safari.processIdentifier, SIGTERM)
}
SIGTERM instead of SIGKILL, referencing from here
Of course, make sure you notify the user of this activity since this may cause negative impact on the user-experience (for example, user-generated contents in the targeted application are not saved before terminating)
It is certainly possible via an applescript directly IF:
your app is not running sandboxed (note that if you plan to distribute it via the App Store, your app will be sandboxed)
OR
your app has the necessary entitlements to use applescript: com.apple.security.scripting-targets (apple needs to approve that AND you need to know which apps to target. this isn't a blanket permission)
then
https://apple.stackexchange.com/questions/60401/how-do-i-create-an-applescript-that-will-quit-an-application-at-a-specific-time
Can you execute an Applescript script from a Swift Application
if you aren't going for App Store complicity anyways, you might also use NSTask directly
scripts / code snippets:
How to force kill another application in cocoa Mac OS X 10.5
Can you execute an Applescript script from a Swift Application
short & sweet: technically yes, 'politically' maybe :D
I'd like to include a button in my Mac app which, when pressed, will launch the user's default calendar app. Preferably, I'd like to have the calendar open to a certain date.
This is for OS X Mountain Lion.
Is there a general way to do this?
Edit:
FWIW, this is what I'm doing now:
- (IBAction)launchCalendarApp:(id)sender
{
[[NSWorkspace sharedWorkspace] launchApplication:#"/Applications/Calendar.app"];
}
I know hardcoding the path like this is a bad idea which is why I'm asking the question.
Update:
This is what I ended up doing:
- (IBAction)launchCalendarApp:(id)sender
{
NSWorkspace *sharedWorkspace = [NSWorkspace sharedWorkspace];
NSString *iCalPath = [sharedWorkspace absolutePathForAppBundleWithIdentifier:#"com.apple.iCal"];
BOOL didLaunch = [sharedWorkspace launchApplication:iCalPath];
if (didLaunch == NO) {
NSString *message = NSLocalizedString(#"The Calendar application could not be found.", #"Alert box message when we fail to launch the Calendar application");
NSAlert *alert = [NSAlert alertWithMessageText:message defaultButton:nil alternateButton:nil otherButton:nil informativeTextWithFormat:#""];
[alert setAlertStyle:NSCriticalAlertStyle];
[alert runModal];
}
}
It sounds like all of the possible ways of doing this are workarounds until a better API is developed. My solution is similar to Jay's suggestion. I'm using the bundle identifier to get the path because I think it is a little less brittle. Apple is unlikely to change the bundle ID in the future even if they (or the user) decides to rename the app. Unfortunately, this method doesn't get me to a specific date. I will investigate further some of the other suggestions (using ical:// etc.) when I have more time.
Update 2:
NSGod has a terrific answer below that also opens the Calendar to a specific date provided your app is not sandboxed.
Note: I was still researching this while you updated with what you used, but I'll add this FWIW.
Using the bundle identifier of the application is generally a more robust way to refer to an app then using the name alone, as a user could move or rename the app in OS X, but they can't easily change the bundle identifier. Moreover, even while Apple renamed iCal.app to Calendar.app, the CFBundleIdentifier is still com.apple.iCal.
if (![[NSWorkspace sharedWorkspace]
launchAppWithBundleIdentifier:#"com.apple.iCal"
options:NSWorkspaceLaunchDefault
additionalEventParamDescriptor:nil
launchIdentifier:NULL]) {
NSLog(#"launching Calendar.app failed!");
}
The above code will work even if your app is sandboxed. You could potentially try to create a custom NSAppleEventDescriptor that would specify the equivalent of something like the following AppleScript code, but it will likely be denied because of the sandbox:
view calendar at date "Sunday, April 8, 2012 4:28:43 PM"
If your app doesn't have to be sandboxed, it's much easier if you use the Scripting Bridge, and with that method it's possible to select a specific NSDate.
Sample project using ScriptingBridge: OpenCalendar.zip
In that project, I use the following code:
SBCalendarApplication *calendarApp = [SBApplication
applicationWithBundleIdentifier:#"com.apple.iCal"];
[calendarApp viewCalendarAt:[self.datePicker dateValue]];
That will launch Calendar.app/iCal.app and change the calendar to the specified date.
So it sounds like for now you'd either have to resort to a hard wired approach, e.g.
// Launches Calendar.app on 10.7+
[[NSWorkspace sharedWorkspace] launchApplication:#"Calendar"];
Or use the URL scheme using what's supported by Calendar/iCal on OS X (pointed out by NSGod in comments below) similar to URL Scheme for opening the iCal app at a date or event?
:
// Launches iCal (works at least with 10.6+)
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:#"ical://"]];
You might try using EventKit to create a EKCalendarItem instance of the desired date and time, open the event, then remove it immediately thereafter. If it's well-timed, it may not even visibly blink on/off the user's calendar.
It's another kludge, but until NSWorkspace has an -openDate: method, kludges are the only recourse.
As discussed on this thread, it seems there's no url scheme to launch iCal
URL Scheme for opening the iCal app at a date or event?
My end goal is to determine the most-recently-used web browser. I.e., a user may have both Safari and Firefox running, but which were they using most recently?
And so, I'm trying to enumerate the open apps, ordered by their window / visibility.
Does Cocoa / Applescript offer a way to retrieve this information?
You can use NSWorkspace's runningApplications method and NSRunningApplication's launchDate property to get you close to what you need.
Check out what the output if this code bit looks like in your console:
NSArray * arrayOfRunningApps = [[NSWorkspace sharedWorkspace] runningApplications];
if(arrayOfRunningApps)
{
for(NSRunningApplication * aUserApp in arrayOfRunningApps)
{
NSLog( #"%# launch time is %#", [aUserApp localizedName], [aUserApp.launchDate description] );
}
}
As for sorting on some criteria, that's really up to your implementation to do.
A couple caveats: these api's were introduced as of Snow Leopard (10.6) and
they only work on apps that the user can see (in the dock), not UNIX processes or admin/root daemons or whatever.
And I'm not certain about Applescript yet, but I'm hoping you'll be able to use this information to get to where you need to go.
I am developing a simple application which has to send an SMS message from the app itself instead of launching the native Text app.
Here's my action now. What should I change to achieve my desired functionality?
-(IBAction)startButtonPressed
{
NSString *phoneNumber = #"13136296693";
NSString *url = [NSString stringWithFormat: #"sms:%#",phoneNumber];
NSLog(#"Send SMS to: %# ", url);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
}
Thanks!
Thomas
If I'm not mistaken I think sending text messages via your own application is only available in the iPhone 4.0 SDK.
Can't be done with the current SDK. I believe Apple announced that applications in iPhone OS 4.0 will be able to do this, using a similar interface to the existing MFMailComposeViewController malarkey.
Here's what apple says:
https://web.archive.org/web/20140604143837/http://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/SystemMessaging_TopicsForIOS/Articles/SendinganSMSMessage.html
Here's a tutorial fon another forum.
http://iosdevelopertips.com/core-services/how-to-send-an-sms-progammatically.html
It's still not entirely automated. The user has to tap the send button. I haven't gotten it working yet. Tell me if you have better luck. If you can think of a way for me to program my app to "tap" the send button instead of the user, let me know.