A small menubar app that allows you to switch between R versions quickly (if you have multiple versions of R framework installed). https://rud.is/rswitch
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.4 KiB

5 years ago
//
5 years ago
// HandleRSwitch.swift
5 years ago
// RSwitch
//
// Created by hrbrmstr on 8/24/19.
// Copyright © 2019 Bob Rudis. All rights reserved.
//
import Foundation
import Cocoa
extension AppDelegate {
// The core worker function. Receives the basename of the selected directory
// then removes the current alias and creates the new one.
5 years ago
@objc func handleRSwitch(_ sender: NSMenuItem?) {
5 years ago
5 years ago
let item = sender?.representedObject as! String
let fm = FileManager.default
5 years ago
let title = sender?.title
5 years ago
let rm_link = (RVersions.macos_r_framework as NSString).appendingPathComponent("Current")
5 years ago
let title_link = (RVersions.macos_r_framework as NSString).appendingPathComponent(item)
5 years ago
5 years ago
do {
5 years ago
try fm.removeItem(atPath: rm_link)
5 years ago
} catch {
5 years ago
self.notifyUser(title: "Action failed", text: "Failed to remove 'Current' alias" + rm_link)
5 years ago
}
do {
try fm.createSymbolicLink(
5 years ago
at: NSURL(fileURLWithPath: rm_link) as URL,
withDestinationURL: NSURL(fileURLWithPath: title_link) as URL
5 years ago
)
self.notifyUser(title: "Success", text: "Current R version switched to " + title!)
4 years ago
// self.notifyUserWithDL(title: "Success", subtitle: "Subtitle", text: "Current R version switched to " + title!)
5 years ago
} catch {
5 years ago
self.notifyUser(title: "Action failed", text: "Failed to create alias for " + title_link + " (\(error))")
5 years ago
}
}
}